[SOLVED] Attempting to delete files that are older than 90 days, but not directories
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Attempting to delete files that are older than 90 days, but not directories
Hi everyone;
Sorry if this is another eye roller, I tried going through the manual and wasn't sure, I tried searching around and couldn't find a specific answer to my question, which is THIS:
I want all files that are older than 90 days in this one particular directory and all sub directories to be removed. However, when I ran this command, it also ended up deleting a bunch of sub directories. (I'm not sure why, as no files had gone through them for the past 90 days?)
I don't want directories to be deleted, only files, this is the command I used after doing a bit of searching, I decided it was the best:
the 'stopper' directory has a ton of other sub directories (well, not anymore!) and as I said, I'd like for it to only delete files and not directories, any assistance would be appreciated.
you didn't set "find" to search only for regular files (option -type f);
you ran a rm -rf on everything "find" found, so all subdirectories older than 90 days got wiped. Still puzzles me why almost everyone issues an "exec rm -rf {}" command while "find" comes itself with a -delete option...
I suggest you try the following:
Code:
find /opt/files/users/stopper/ -type f -mtime +90 -delete
You should remove the delete command first to see which files will be deleted and then, when happy with the result, add it again.
-type f is regular file, so it should only find regular files at that point, and not directories, but it'll still search all the directories? I don't have a manual for -rf so I'm not actually sure what they're doing, I just get 'no manual entry for rf'
you didn't set "find" to search only for regular files (option -type f);
you ran a rm -rf on everything "find" found, so all subdirectories older than 90 days got wiped. Still puzzles me why almost everyone issues an "exec rm -rf {}" command while "find" comes itself with a -delete option...
I suggest you try the following:
Code:
find /opt/files/users/stopper/ -type f -mtime +90 -delete
You should remove the delete command first to see which files will be deleted and then, when happy with the result, add it again.
Thank-you for the fast response. The reason I used 'exec rm {}' is that several 'how to' websites reference to it. I am a huge newbie, I see the massive list of files, what do I need to add to that so I see a time stamp of the files, similar to a 'ls -ltr'?
jlinkels: Sorry, I meant I was attempting to manual for 'rm', but I was typing 'rf' instead as it was 5:30AM and my brain was a little fried. Thanks for everyones help.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.