Visit Our UNIX and Linux User Community

mv command: mv vs rename operation

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers mv command: mv vs rename operation
# 1  
Old 06-23-2010
mv command: mv vs rename operation

Hi all,

I wish to know about a simple concept of mv command in UNIX. Is moving a file to a different directory takes longer than renaming it in the same direcotry using the mv command?

The scenerio is that I have to transfer a file from one directory to a location which is regularly scanned by some "program" for the file. This "program" moves the file to some other system. Now if the input file is huge, the "program" may transfer the file before the whole file is moved to this location.

So I decided to move the file with a different name to the second location. Once this operation is complete then I would rename the file to the original name so that the "program" can transfer the file.

My query is that whether the renaming would take same time as move operation? If so, then my approach may not work......Please suggest......

Thanks in advance.
# 2  
Old 06-23-2010
The mv command changes the pointer to the file not the file itself. However, if the destination is on another file system (NFS mount are included here) a copy operation occurs first.

In other words, if you are moving a file from one file system to another, the file is actually copied. If you are moving the file within the same filesystem, the pointer to the file is changed but the data stays in place.

# 3  
Old 06-23-2010
Hi, on unix systems you rename files by using the command mv. A mv within the same filesystem is instantanious and boils down to a rename. A mv to a different filesystem is like a copy operation followed by a remove.

A move to a different directory should take just as long as a move in the same directory as long as both directories are on the same filesystem.
# 4  
Old 06-23-2010
A "mv" within the same mounted filesystem just changes the name entry for that inode and is very quick. The inode number does not change and the data does not move.

A "mv" across mounted filesystem boundaries will physically copy the file.

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

FTP rename command help

I have to ftp and rename the file with #finished# extension after successfully transfer. In some environments the command rename ABCD.dat ABCD.#finished# is working fine, but some environments its not working, I have to use escape character something like : rename ABCD.dat ABCD.\#finished\# Why is... (3 Replies)
Discussion started by: srikanth38
3 Replies

2. UNIX for Beginners Questions & Answers

Move and Rename in One Command

Hey all, I really need help with some homework I'm having on UNIX. This probably sounds stupid, but I'm being asked to move a file to a specific directory and rename it a specified name in one command. I know how to do it in more than one command, I just can't seem to figure it out using only one... (1 Reply)
Discussion started by: ayylmao12
1 Replies

3. Shell Programming and Scripting

Having trouble with find rename jpg command

Hi, I have a large series of directories and subdirectories with many jpgs in them. I need to do two things: 1. Create a copy of each jpg found within it's own subdirectory 2. Rename this copied jpg such that apple.jpg becomes apple_m.jpg I have tried to run the following commands in... (1 Reply)
Discussion started by: atharvan13
1 Replies

4. Shell Programming and Scripting

sed command to skip the first line during find and replace operation

Hi Gurus, I did an exhaustive search for finding the script using "sed" to exclude the first line of file during find and replace. The first line in my file is the header names. Thanks for your help.. (4 Replies)
Discussion started by: ks_reddy
4 Replies

5. Shell Programming and Scripting

ksh command to rename all files with no extension

hi! i want to rename all files with no extension with the extension DAT. with this command ls |grep -v "\\." i can list files but i dont know how i am going to rename them.. so i tried FILE_LIST=ls |grep -v "\\." for TEST_FILE in ${FILE_LIST} do mv $TEST_FILE... (2 Replies)
Discussion started by: kouppoua
2 Replies

6. Shell Programming and Scripting

Column operation : cosne and sine operation

I have a txt file with several columns and i want to peform an operation on two columns and output it to a new txt file . file.txt 900.00000 1 1 1 500.00000 500.00000 100000.000 4 4 1.45257346E-07 899.10834 ... (4 Replies)
Discussion started by: shashi792
4 Replies

7. Shell Programming and Scripting

Rename file using sed command

Greetings, I am very new to the UNIX shell scripting and would like to learn. However, I am currently stuck on how to process the below sample : Filename : DOCabcdef24387987ab90d.xml Pattern "DOC"+any character using and +".xml" And i want to change the second part of that file (any... (20 Replies)
Discussion started by: fanny_tirtasari
20 Replies

8. Shell Programming and Scripting

sed command for substring operation

Hi All, Input=abcDEF_1.6k1 I need to use ‘sed' command to get 1.6 value and store to some variable from the given input. Please help me in getting the command. Regards, Kalai (2 Replies)
Discussion started by: kalpeer
2 Replies

9. Shell Programming and Scripting

how to rename all the files with one command?

How do i rename all the files using a script ? My server create log files and save them with numbering behind the name. for e.g. daily_20080101.log.0001 and so on ... How do a script and crontab it to remove all the numbering? Please help thanks. (2 Replies)
Discussion started by: filthymonk
2 Replies

10. Shell Programming and Scripting

how to rename multiple files with a single command

Hi I have following list of files at a path: 01.AR.asset 01.AR.index 01.AR.asset.vf 01.AR.asset.xv I want to rename all these files as follows: 73.AR.asset.Z 73.AR.index.Z 73.AR.asset.vf.Z 73.AR.asset.xv.Z Can any body give me a single command to acheive the above results. ... (5 Replies)
Discussion started by: tayyabq8
5 Replies

Featured Tech Videos