How do I prevent a folder inside of /tmp from being cleaned up?
This question is about Ubuntu 14.10 on my developer laptop.
I've got a folder in /tmp
that is used by an application to put temporary stuff in there. This application usually makes a temporary folder in my homedir and deletes it afterwards. For some reason that doesn't work when the homedir is encrypted. So instead, I made a symlink to /tmp/foo
inside my homedir. My application can write there and make it's temporary subfolder.
Now /tmp/foo
gets deleted every time I reboot my machine. Until now I've just recreated the folder manually after reboot. Now I learned in How is the /tmp directory cleaned up? that there is a job doing that.
I've looked at /etc/init/mounted-tmp.conf
but my bashfu and especially my findfu are not sufficient to do what I want. Here's an excerpt from that file:
EXCEPT='! -name . ! ( -path ./lost+found -uid 0 ) ! ( -path ./quota.user -uid 0 ) ! ( -path ./aquota.user -uid 0 ) ! ( -path ./quota.group -uid 0 ) ! ( -path ./aquota.group -uid 0 ) ! ( -path ./.journal -uid 0 ) ! ( -path ./.clean -uid 0 ) ! ( -path "./...security*" -uid 0 )' # Remove all old files, then all empty directories find . -depth -xdev $TEXPR $EXCEPT ! -type d -delete find . -depth -xdev $DEXPR $EXCEPT -type d -empty -delete
What I want to do is add a condition that makes it delete everyting inside /tmp/foo
, but not /tmp/foo
itself. How do I do that?
/etc/init/mounted-tmp.conf
is part of the mountall
package, so any updates on that package and the suggested changes will be reverted.
$ sudo dpkg -S /etc/init/mounted-tmp.conf
mountall: /etc/init/mounted-tmp.conf
Instead, according to the Filesystem Hierachy standard (FHS);
Regarding /tmp:
Programs must not assume that any files or directories in /tmp are preserved between invocations of the program.
Regarding /var/tmp:
The /var/tmp directory is made available for programs that require temporary files or directories that are preserved between system reboots. Therefore, data stored in /var/tmp is more persistent than data in /tmp.
So you should change your symbolic link to use /var/tmp
instead of /tmp
.
Not strictly an answer to your question, but you might find /var/tmp
to be a more suitable location, as it doesn't get cleaned up over a reboot. It's designed for temporary files that should not be automatically discarded after a short time.
What I often do, however, is create myself a folder under /opt to store random things I don't want in home. That's a suitable place to put things that are outside the main OS's control.