开发者

How do I delete old[er] files from my centos /tmp directory EXCEPT certain files still in use? [closed]

开发者 https://www.devze.com 2023-02-04 22:34 出处:网络
Closed. This question is off-topic. It is not currently accepting answers. 开发者_运维问答 Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed. This question is off-topic. It is not currently accepting answers. 开发者_运维问答

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 11 years ago.

Improve this question

I 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)

0

精彩评论

暂无评论...
验证码 换一张
取 消