find and delete files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers find and delete files
# 1  
Old 08-18-2010
find and delete files

hi all ,

i want to find and interactively delete all the files having size greater than 20 bytes using "find" and other commands.....
# 2  
Old 08-18-2010
Hi.

Using the -ok option:

Code:
find /path/to/files -type f -size +20c -ok rm {} \;

# 3  
Old 08-18-2010
Notes: Wrong solutions, which are not interactive.

by -exec

Code:
find /path/to/files -type f -size +20c -exec rm {} \;

by xargs

Code:
find /path/to/files -type f -size +20c |xargs rm


Last edited by rdcwayx; 08-19-2010 at 09:33 PM..
# 4  
Old 08-19-2010
Beware. Post #3 is not interactive and will delete all files larger than 20 bytes.


Because there is much variation in the "find" command, what Operating System are you running?

---------- Post updated at 14:00 ---------- Previous update was at 13:44 ----------

If you have unix not Linux (and don't have the "-ok" option).

Code:
find /path/to/files -type f -size +20c -exec rm -i {} \;

The "rm -i" command will ask for "y" or "n" confirmation for deletion of each file.
# 5  
Old 08-19-2010
Quote:
Originally Posted by methyl
If you have unix not Linux (and don't have the "-ok" option).
Every "UNIX" find has the -ok option.
# 6  
Old 08-19-2010
Quote:
Every "UNIX" find has the -ok option.
Not true, although I would expect the option in modern mainstream unix.
# 7  
Old 08-19-2010
Quote:
Originally Posted by methyl
Beware. Post #3 is not interactive and will delete all files larger than 20 bytes.


Because there is much variation in the "find" command, what Operating System are you running?

---------- Post updated at 14:00 ---------- Previous update was at 13:44 ----------

If you have unix not Linux (and don't have the "-ok" option).

Code:
find /path/to/files -type f -size +20c -exec rm -i {} \;

The "rm -i" command will ask for "y" or "n" confirmation for deletion of each file.
yes, you are right, I don't see the word "interactively "
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find command to delete the files

Hi All, I've created 2 files touch -t 201309101234 aa10 touch -t 201309111234 aa11 Exact 60 days before from today date is SEPT 12th . As per the following command as i gave +60 means the files which were created before sept12th should be deleted find /etc/logs/*aa* -type f -atime +60... (5 Replies)
Discussion started by: smile689
5 Replies

2. Shell Programming and Scripting

Find modify and delete files

hi every one. one of my friends has writen this script and send it to me. this script can find files that add-delete-modify and also send an alert by email i'm not catch all part of it. can anyone explain me how this work #!/bin/bash START="a.txt" END="b.txt" DIFF="c.txt" mv ${START}... (4 Replies)
Discussion started by: nimafire
4 Replies

3. UNIX for Dummies Questions & Answers

Find command to delete old files

Hi, I want to delete all the log files that was created on year 2008. My command is not working. Any idea? find . -name '*.log' -mtime 1460 -exec ls -lt {} \; Thank you. (2 Replies)
Discussion started by: samnyc
2 Replies

4. Shell Programming and Scripting

Script to go Into Directories and Find/Delete files

I have a task, I usually do manually, but with growing responsibilities I tend to forget to do this weekly, I want to write a script that automates this, but I cant seem to work it out in my head, I have the shell of it out, but need help, and you guys have helped me with EVERY problem I have... (5 Replies)
Discussion started by: gkelly1117
5 Replies

5. UNIX for Dummies Questions & Answers

Script to find the files and delete them

This is a real world problem so I think you might found this interesting. We have servers which are shared by multiple team members. Each team member has its own user id and home directory. Now with time each user starts creating files which in end caused the disk to be full. Now for creating a... (5 Replies)
Discussion started by: Rohit06
5 Replies

6. Homework & Coursework Questions

Find and delete empty files and directories

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Need to make a script, to remove all empty files and folders from current category. It also should show the name... (2 Replies)
Discussion started by: Itixop
2 Replies

7. Shell Programming and Scripting

Script to find files and delete it by comparing

I have a directory where lot of "gzip" files are dropped in every 5 minutes. There is an application which will process these gzip and move it to another directory but will leave a gzip.out file with lot of output data. I need to remove all the outfiles except for the one which is being... (1 Reply)
Discussion started by: gubbu
1 Replies

8. Shell Programming and Scripting

find files for a particular date and delete

How can I delete files for a particular date ? I apologize in advance If there is solution please put the link. Thanks, (5 Replies)
Discussion started by: jville
5 Replies

9. Shell Programming and Scripting

Find files including subdirectory and Delete

Hello Experts, I m newbie. Could u pls help me to write script on Sun solaris- I have backup directory "/var/opt/backup/" where files are backed up in different directory "backup1" "backup2" "backup3". I want to write a shell script which i will put in crontab and daily midnight it will... (1 Reply)
Discussion started by: thepurple
1 Replies

10. UNIX for Dummies Questions & Answers

batch delete using find, files with # character

UPDATE: Sorry, disregard this. It did work, I made a mistake; I just shouldn't have been using maxdepth. I do think it is good to know, however, that find | grep '#' | xargs rm will "clean up" funnily named files in a directory. Of course, some of those funnily named files are there... (0 Replies)
Discussion started by: tphyahoo
0 Replies
Login or Register to Ask a Question