How do I delete old[er] files from my centos /tmp directory EXCEPT certain files still in use? [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this questionI need to figure out how to automatically remove most files from my /tmp directory on a centos server. The directory keeps filling up with junk that needs to go, however there are files in there that need to stay, so:
How can I delete files in /tmp that are over 24 or so hours old AND keep files with certain name patterns?
I believe Centos has tmpwatch
.
You can use find
to accomplish this.
find -mtime 1 -regex [your_pattern_here] -exec rm -f {} \;
mtime
looks for any files older than N days old, and the [your_pattern_here]
in this case would be the pattern of files you want to keep. It'd be best to do this without the exec
portion at the end first to make sure it's finding the files you're expecting (or more importantly, not finding files you want to keep)
精彩评论