This will delete all files and directories old than 7 days within /tmp or other directory you specify, it will only look for files within that directory and not sub-directories.
find /tmp/ -maxdepth 1 -mtime +7 -exec rm -rf {} ;
- -maxdepth mean how deep to look for files.
- -mtime means the modified time.
This will list all the files that the first command would have deleted without actually deleting the files.
find /tmp/ -maxdepth 1 -mtime +7
Be very careful with the first command, it could render your system useless and delete other files. Do not use “/tmp/.*”, it could delete files outside of your directroy.
Leave a Reply