Khanetor
Khanetor

Reputation: 12304

Automatically cleanup tmp directory in Unix

I am implementing my own file cache server using Play framework, and I put my cached files in /tmp directory.

However I do not know how the OS manages the /tmp directory. What I wish to know is if the OS will automatically cleanup some files that are old enough, or have not been accessed for a long time.

I am running my server in a Docker container, based on Debian jessie.

Upvotes: 1

Views: 3811

Answers (1)

Sobrique
Sobrique

Reputation: 53478

Your OS won't clean up /tmp. Some Unix variants clear it out at reboot. You will need to do this yourself.

 find /tmp/yourpath -mtime +30 -type f -exec rm {} \;

For example.

But Docker is a bit of a special case, as the containers are an encapsulation layer. That find will still do the trick, but you could probably just dump and restart your container 'fresh' and trash the old one.

Upvotes: 2

Related Questions