If you have binary programs or scripts generating files in /tmp and you want to grab them before they disappear, then use this script. You can copy them. If you copy them to within a folder in /tmp and you can use a hardlink copy (recall a hardlink copy is a quick copy, that doesnt take up extra bytes,but only works within the same “volume”/”filesystem”). If you copy them to another folder, outside of /tmp, then just use regular copy.

  1. install inotify-tools, apt-get install inotify-tools
  2. Modify the MONITOR folder (the folder you will monitor for new files)
  3. Modify CLONE folder (where you will copy the final)
  4. Uncomment cp -rl line if MONITOR and CLONE are in the same volume, because you can utilize hardlinks (hardlink copy = copy -l)
  5. Uncomment cp -r line if MONITOR and CLONE are in different volumes, so you will need to use regular copy
  6. run the script. or copy paste it (since its in a subshell, this is a good copy pasteable)

Script:

Example, in one shell:

In another shell, create a file into tmp.

In first shell you will see:

You can go to /root/tmpnew to see the files

NOTE: mkdir has extra slash, double slash, //, bash ignores double slashs as it knows they will appear often. So /folder//somefolder//somefile is the same as /folder/somefolder/somefile.

Leave a Reply

Your email address will not be published. Required fields are marked *