LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   About deleting a files (https://www.linuxquestions.org/questions/linux-newbie-8/about-deleting-a-files-517864/)

combilli 01-09-2007 09:10 PM

About deleting a files
 
Hi.
I got a mission. It's to delete some files in a folder that was created before in a specified date.

I only know to use ls -la to check files date.
But the problem is there are too much files and lots documents directory..

Is there a way to check the files date and delete them?

thx for help.

btmiller 01-09-2007 10:54 PM

Use find in conjunction with exec, e.g.

Code:

find . -mtime +5 -mtime -7 -exec rm -i {} \;
This will remove all files last modified between 5 & 7 days ago.

Note that I've specified the -i flag to rm to make it prompt before removing a file. This is always a good idea when doing magic with find + rm to make sure you only remove the files you want to remove. Remember, there's no undelete on the command line (alternatively you could mv the found files to another directory for later perusal/removal, e.g.:

Code:

find . -mtime +5 -mtime -7 -exec mv {} ~/files_for_deletion/ \;
See "man find" for more details about what you can do with find. it is a very powerful tool!


All times are GMT -5. The time now is 04:20 AM.