Search code examples
unixdisk

How does UNIX handle a move of a file between two disk file systems?


I have three directories on a UNIX box, as described below:

/tmp mapped on /dev/mapper/data-tmpVol1
/var mapped on /dev/mapper/data-varVol1
/opt mapped on /dev/mapper/data-optVol1
  1. If I perform a move operation from /tmp to /var, will the UNIX do in fact a copy since there are two different file systems behind scene?

  2. If I want an instant move, is it better to copy the file first in a /var/staging and perform a move from /var/staging to /var/input?

Context around the issue: I have a process which scans for files in /var/input, and I've seen cases when it picked up half-copied files (when moving directly from /tmp to /var/input).

Regards,

Cristi


Solution

  • When moving across file systems, you may like to create a file in the destination directory with a temporary filename, e.g. my-file.txt~. The scanning process must ignore such temporary filenames. When the file is complete you rename it to the final name. This way when the file (with a final name) exists it is complete, or it doesn't exist at all.