Silly question - how does the "mv" command work?

I know this may sound really elemental, but I'm trying to figure out if I'm correct.

I have a script that moves a file from a temp directory to (what I am calling) a pickup directory.

On another machine, I have this "other program" that scans the contents of the pickup directory for a specific file name. If the file name exists, the program goes forth and does a bunch of routines ... (really not plausible to my question)

However, I have a feeling that this "other program" is grabbing this file too soon as the "mv" hasn't successfully completed writing the files contents; perhaps just the filename.

I did a test on the "other program" and the scan looks for the said file (in a while loop) approx. 22,000 within 10 seconds (a timeout).

The size of the "moved" file varies but is averages at about 200-300 bytes.

Can someone tell me if the move command first creates the file then writes?

Thank you!

If both directories are in the same file system only the inode table is updated, the file does not actually move

---------- Post updated at 12:01 PM ---------- Previous update was at 11:54 AM ----------

If the two directories involved in the mv are on different file systems, the a copy and delete is done
However, unix systems will show the file in a ls as soon as it is opened for writing, so your second program should confirm that the file is not in use (use fuser), otherwise you may process a partial file.

Actually, the file is being moved to an NFS mounted directory. Any ideas?

When you mv the file from its original location to the pickup location, when finished, create or move a second file with the same name as the data file, but a different extension (eg data.dat and data.job)
Have your second process only process .dat files for which there is a equivalent .job file.

Can the scanning program be configured to skip files beginningin . ? That way, you could upload it as ".filename", so it will be skipped, then rename it to "filename" once ready to be processed.

However the inode does not change when moving a file within the same filesystem:

$ ls -i file1
    139787 file1
$ mv file1 file2
$ ls -i file2
    139787 file2

Is the same as creating a hard link, and deleting the original reference:

$ ls -i file1
    139787 file1
$ ln file1 file2
$ rm file1
$ ls -i file2
    139787 file2