"Find" command
Hello
I would like to achieve following results: 1) delete all the files and folders that are older than 1 month 2) delete all the files that have .pcap extension, its size is greater than 1M and are older than 14days Assuming that: - all the files and folders are located in /home/user/ - directories are 1 lvl depth (so /home/user/One/, /home/user/Two/ ...) from the perspective of /home/user directory i have prepared commands for this: 1) find /home/user/ -maxdepth 1 -mtime +30 -exec -exec rm -rf "{}" \; 2) find /home/user/ -maxdepth 1 -type f -size +1M -mtime +14 -exec rm -rf *.pcap "{}" \; Could you please confirm or provide me with other wayout of how to achieve my goals. Thanks, Mac |
Why not try out these commands yourself (easy enough to set up a directory structure for them to work on) and see if they give you what you want.
jdk |
Hi,
I don't want to delete all the files :) Just want to double check first. Thx. |
As mentioned, Copying some files to an alternate directory and testing will always be the best way to double check.
Anyway, Cleaned the commands up, and used full path to ls to ignore any aliases. And used ls to prove that we are looking at the right files. Just change ls -alh to rm -f once you are satisfied. Code:
find /home/user/ -maxdepth 1 -mtime +30 -exec /bin/ls -alh {} \; |
Thanks for the hint.
I am about to check this out and give you feedback. |
Quote:
|
yeah good point as well...
Thanks |
For your second command you should use -name "*.pcap" as search criteria otherwise if there is some file that is larger than 1M and older than 14 days you would remove ALL pcap files.
Cheers |
Code:
find /home/user/ -maxdepth 1 -type f -size +1M -mtime +14 -name "*.pcap" -exec rm -rf "{}" \; Thanks a lot for prompt answers. |
gnu find has a -delete action built-in, so there's no need to "-exec rm {}" any more.
If you want to test the command before you commit to it, just run find with the -print option first, of course. This will list out all the files that will be processed when you finally use -delete (or -exec or any other action option). Here are a couple of good links about using find: http://mywiki.wooledge.org/UsingFind http://www.grymoire.com/Unix/Find.html |
Thanks David. i've overlooked -delete and -print param.
|
All times are GMT -5. The time now is 09:48 PM. |