The switch you need is --parents
, e.g.:
jim@prometheus:~$ cp --parents test/1/.moo test2/
jim@prometheus:~$ ls -la test2/
total 42
drwxr-xr-x 3 jim jim 72 2010-09-14 09:32 .
drwxr-xr-x 356 jim jim 43136 2010-09-14 09:32 ..
drwxr-xr-x 3 jim jim 72 2010-09-14 09:32 test
jim@prometheus:~$ ls -la test2/test/1/.moo
-rw-r--r-- 1 jim jim 0 2010-09-14 09:32 test2/test/1/.moo
Most of my requirements have already been available in Debian.
By default, /etc/default/rcS
sets environment variable TMPTIME=0
.
$ man rcS
:
TMPTIME
On boot the files in /tmp will be deleted if their modification time is more than TMPTIME days ago. A value of 0 means that files are removed regardless of age. If you don't want the system to clean /tmp then set TMPTIME to a negative value (e.g., -1) or to the word infinite.
Looking in /lib/init/bootclean.sh
, I found out that the quota file './aquota.user(owned by root) is excluded from removing. Conclusion: quota settings will persist during reboots and
TMPTIME=0can safely be set in
/etc/default/rcS`.
To keep /tmp
clean while running, I installed tmpreaper
.
To activate it, SHOWWARNING=true
should be commented. Furthermore, TMPREAPER_TIME=7d
should be uncommented in order to clean files older than 7 days.
A 1GB temp disk was created and formatted ext3 with:
# dd if=/dev/zero of=/var/tmpdisk bs=1K count=1000000
# mkfs.ext3 -F /var/tmpdisk
Mounting it at boot-time required a change in /etc/fstab
:
# /var/tmpdisk /tmp ext3 loop,rw,nosuid,noexec,nodev,quota 0 0
Since /var/tmpdisk
is not a real device, it should be mounted as loop device, hence loop
. nosuid,noexec,nodev
have been added as a layer of security to prevent common exploit kits from abusing /tmp
. Finally, quota
enables quota for the disk.
After modifying /etc/fstab
, I ran mount -a
to mount the new /tmp
disk. Since /tmp
should be world-writable, and users should not be able to delete files they do not own, the directory permissions should be changed too:
# chmod 1777 /tmp
Activate quotas:
# quotacheck /tmp
# quotaon /tmp
Now /tmp
fully suits my needs with quotas activated and auto-cleaning junk files. The only thing I have to do is adding quotas for each user by running edquota username
.
Best Answer
Possible with LD_PRELOAD and some libraries, depending on the software. The easiest thing might be to put something in rc.local that will create the directories as a final step in the boot procedure.
If you wanted to make sure the directories are there continuously, you could have a cron job running that created the dirs (using mkdir -p possibly).