How To Remove Files Older Than 1 Day Recursively
We are decent bash scripter and not now hot to remove older files for example 1 day.
rm command do not have this type of option to use easily. I think adding this type of feature make a lot of system administrators more happy.
Now we can look our solution. We will use find command to find files older than 1 day remove them.
$ find /tmp -mtime +1 -type f -name '*.tmp' -delete
- find is the command we use
- /tmp is the directory where files resides
- -mtime provide time option and +1 means older then one day
- -type provides file types here we set file but we can use directory, socket etc
- –name ‘*.tmp’ filters files according to their names. we just want tmp extension files
- And the magic resides here -delete will delete the files matching provided criterias