The most voted solution here is missing -maxdepth 0 so it will call rm -rf for every subdirectory, after deleting it. Havent tried, someone may confirm in comments. ![]() This should work on Ubuntu, Suse, Redhat, or pretty much any version of linux. find supports -delete operation, so: find /base/dir/ -ctime +10 -delete I think theres a catch that the files need to be 10+ days older too. And date with -d option which is not POSIX compatible. ![]() bin/bash Simple script to delete files older than specific number of days from FTP. How can I improve this to only delete files older than x days (e.g. You need to uncomment STOREDAYS6 to specify count manually. We’ll use this in order to figure out what files are older than a certain number of days, and then use the rm command to delete them.įind /path/to/files* -mtime +5 -exec rm \ at the end is required to end the command. 1 I'm currently using this cron job to delete stalled temp files in a particular location. In case if there are no files, I should log an error saying no files to delete. ![]() I have CSV files get updated every day and we process the files and delete the files older than 30 days based on the date in the filename. find has options to read files creation ( ctime ), access ( atime ) and modification ( mtime ). The find utility on linux allows you to pass in a bunch of interesting arguments, including one to execute another command on each file. Hi All, I am using below code to delete files older than 2 days. This question already has answers here : Closed 3 years ago. Sometimes, you may need to delete files older than x days.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |