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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Silly question - how does the "mv" command work?
# 1  
Old 04-16-2010
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!
# 2  
Old 04-16-2010
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 ----------

Quote:
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.
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.
# 3  
Old 04-16-2010
Actually, the file is being moved to an NFS mounted directory. Any ideas?
# 4  
Old 04-16-2010
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.
# 5  
Old 04-16-2010
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.
# 6  
Old 04-16-2010
Quote:
Originally Posted by jgt
If both directories are in the same file system only the inode table is updated, the file does not actually move
However the inode does not change when moving a file within the same filesystem:


Code:
$ 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:

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


Quote:
Usually moving files within the same file system is not the same as copying and then removing the original. First a new link is added to the new directory then the original link is deleted. The data of file is not accessed. This is much it is faster than copy and remove. The file still has the same inode.

Last edited by verdepollo; 04-16-2010 at 03:23 PM.. Reason: Clarify
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

"Mv" command does not work in loop, but works manually

Hi there, this may be a beginner's error, but I've been unable to find a solution on my own and by googling, and now I am really stuck on it. I am simply trying to move directories called for example CAT_Run01.ica to a directory with the corresponding number, Run01, in the same directory. For... (2 Replies)
Discussion started by: andrevol
2 Replies

2. Red Hat

"/usr/sbin/hpacucli ctrl all show" command does not work

Dear Concern, We have observed that following command stuck/does not work in some RedHat nodes. Please advise us to troubleshoot the issue. /usr/sbin/hpacucli ctrl all show Note: HP Array Configuration Utility CLI for Linux 64-bit With Best Regards, Md. Abdullah-Al Kauser (3 Replies)
Discussion started by: makauser
3 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. AIX

"/" doesn't work on command prompt for searching commands last typed

When I use "/" to look for a particular command that I typed in the current session it says D02:-/home/user1/temp> /job ksh: /job: not found. D02:-/home/user1/temp> previously it used to fetch all the commands which had job in it.. for example subjob, endjob, joblist etc... may I... (7 Replies)
Discussion started by: meetzap
7 Replies

6. UNIX for Advanced & Expert Users

sometimes "ps -elf" command doesn't work

when i give "ps -elf" or "ps" system gets hung. if i press "^c" come out from it... pls help..what should i do to get it resolved. thanks CKanth (4 Replies)
Discussion started by: srikanthus2002
4 Replies

7. Shell Programming and Scripting

How to get Find command work with a variable passing "*" value?

Hi guy, I have a problem to pass a variable containing '*' value to FIND command. below is the script. It doesn't work by submit below command: rmf.sh name '*.txt' or rmf.sh name *.txt I've tried either optn="-name '$2'" or optn="-name $2"., and there is no luck. ### (script... (5 Replies)
Discussion started by: unxuser
5 Replies

8. UNIX for Dummies Questions & Answers

"man date" command does not work

Hi there I'm logged in as root on a UNIX Spark 10 using a SSH client. I notice that the time on the machine is wrong and I type "man date" in order to receive the options how to change this. When typing "man date" and hitting Enter I get the message "No manual entry for date" Why? Am I... (1 Reply)
Discussion started by: aptit
1 Replies
Login or Register to Ask a Question