Results 1 to 4 of 4
Hey, I just need some help trying to delete multiple directories is a particular directory: This is a fax server running 2.4 kernel. the Interface is all gui but I ...
- 09-15-2010 #1Just Joined!
- Join Date
- Sep 2010
- Posts
- 2
Noob...Need to delete multiple files at once
Hey, I just need some help trying to delete multiple directories is a particular directory: This is a fax server running 2.4 kernel. the Interface is all gui but I can ssh into the box to do more advanced commands. there are over 4k dirs in the /usr/local/share/fsched dir. I can do a ls -l to list them.
drwxr-xr-x 3 mail2ff mail2ff 1024 Sep 13 09:15 00005893
drwxr-xr-x 3 mail2ff mail2ff 1024 Sep 13 09:19 00005894
It would be great to know how to delete all the files that are from Sept 13th.
I have tried ls -l | wc will tell me how many directories are in the fsched folder then:
rm -rf `find . -type d -name "0*" -mtime +30` to remove the files that are 30 minutes old?? Not sure about this but I cant make much progress this way.
I guess I could just delete everything but I would like to understand how to be specific about 'what files" too.
thanks in advance for you help!
- 09-15-2010 #2Linux Newbie
- Join Date
- Apr 2007
- Posts
- 119
-mtime +30 is saying +30*24 hours ago. Check out the man page for find.
I would probably use a combination of ls and grep to sort out what you want if you want certain dates.
- 09-15-2010 #3Just Joined!
- Join Date
- Jul 2008
- Posts
- 81
[QUOTE=bsoth;804651]Hey, I just need some help trying to delete multiple directories is a particular directory: This is a fax server running 2.4 kernel. the Interface is all gui but I can ssh into the box to do more advanced commands. there are over 4k dirs in the /usr/local/share/fsched dir. I can do a ls -l to list them.
drwxr-xr-x 3 mail2ff mail2ff 1024 Sep 13 09:15 00005893
drwxr-xr-x 3 mail2ff mail2ff 1024 Sep 13 09:19 00005894
It would be great to know how to delete all the files that are from Sept 13th.
I have tried ls -l | wc will tell me how many directories are in the fsched folder then:
rm -rf `find . -type d -name "0*" -mtime +30` to remove the files that are 30 minutes old?? Not sure about this but I cant make much progress this way.
-----
To delete directories and contents modified more than 30 minutes ago:
# find . -type d -mmin +30 -exec rm -rf {} +
You don't need to specify -name "0*" unless there really are other directories with names that do not begin with 0 that you want to avoid.
For the sake of safety, you should try the command non-destructively first, e.g.
# find . -type d -mmin +30 -print > /tmp/trial_list
- 09-16-2010 #4Just Joined!
- Join Date
- Dec 2009
- Location
- California
- Posts
- 68
How about this one:
$ ls -l |grep "^d.*Sep 13" |awk '{print $NF}' |xargs rm -rf
Try it in stages to see how it works.
The grep finds all the entries in the output that starts with a "d" and contains "Sep 13" which was the date you mentioned. The "*" doesn't work the way you might expect it to... it matches zero or more occurances of the preceeding character, so you have to have the "." (which means anything) or it won't work.
The awk just prints the last field on the line - which in this case is the file name. The xargs captures stdin and pastes it on the command line.
The rm command has to have the "-r" since you said these were directories. and the "-f" is needed because linux aliases the rm command to rm -i which means interactive.


Reply With Quote