Script to delete files older than unix
But do check your path carefully though. Additionally check file times with 'stat filename'. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Delete files older than 10 days using shell script in Unix [duplicate] Ask Question. Asked 9 years, 1 month ago. Active 2 years, 3 months ago.
Viewed k times. Morgan Thrapp 8, 3 3 gold badges 45 45 silver badges 60 60 bronze badges. Steve88 Steve88 2, 3 3 gold badges 21 21 silver badges 42 42 bronze badges. Did you have a look at man date? Do you need to delete based on the filename or the file's modification time? Add a comment. Active Oldest Votes. Remove it to test your find filter before executing the whole command And take care that. Gilles Quenot Gilles Quenot k 33 33 gold badges silver badges bronze badges.
It depends of the date of the modification, like what ls -l displays. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. Delete only files older than 7 days: -mtime and find Ask Question.
Asked 3 years, 7 months ago. Active 1 year, 9 months ago. Viewed 27k times. Found a few similar questions but were not quite a match. Improve this question. Dehay Dehay 67 1 1 gold badge 1 1 silver badge 2 2 bronze badges. What do you mean by "leaving any sub-directories intact"? Do you mean "don't delete files from sub-directories" or do you mean "don't delete the sub-directories themselves"?
Add a comment. This is the best practice to remove old unused files from your server. So clean it regularly. To do it you can find older files from the backup directory and clean them. This article describe you to how to find and delete files older than 30 days. Here 30 days older means the last modification date is before 30 days.
You can use the find command to search all files modified older than X days. And also delete them if required in single command. Verify the file list and make sure no useful file is listed in above command. Once confirmed, you are good to go to delete those files with following command. Instead of deleting all files, you can also add more filters to find command. Above command will delete only files having. Using the -delete option may fail, if the directory is not empty.
In that case we will use Linux rm command with find command. Here we can execute the rm command using -exec command line option. Find command output will be send to rm command as input.
0コメント