Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 10-13-2010, 09:18 PM   #1
Registered: Oct 2010
Location: Bengaluru, India
Distribution: RHEL 5.1 on My PC, & SunOS / Sun Solaris, RHEL, SuSe, Debian, FreeBSD and other Linux flavors @ Work
Posts: 576

Rep: Reputation: 48
Copying and Moving Operations and their Performance Differences

Let's consider this text file:

[root@mahadeva ~]# ls -ild hello
1566924 -rw-r--r-- 1 root root 150 Oct 14 07:20 hello
I copy (cp) it with another name:

[root@mahadeva ~]# cp hello hello-copy
[root@mahadeva ~]# ls -ild hello*
1566924 -rw-r--r-- 1 root root 150 Oct 14 07:20 hello
1566966 -rw-r--r-- 1 root root 150 Oct 14 07:21 hello-copy
The inode value is changed now.

I move (mv) any of the two files and give it some other name:

[root@mahadeva ~]# mv hello-copy hell-moved
[root@mahadeva ~]# ls -lid he*
1566966 -rw-r--r-- 1 root root 150 Oct 14 07:21 hell-moved
1566924 -rw-r--r-- 1 root root 150 Oct 14 07:20 hello
The inode value is not changed even if I move the file into some other directory:

[root@mahadeva ~]# mv hello-moved /tmp
[root@mahadeva ~]# ls -lid /tmp/hello*
1566966 -rw-r--r-- 1 root root 150 Oct 14 07:21 /tmp/hello-moved

Well, let's suppose the file is very large, say 10 GB of disk space it is consuming.

We perform the above steps. Which operations: cp (copying) or mv (moving) will be more efficient and less time consuming?

The inode number 1566966 which was pointing to the file in my home directory is now pointing to the same file which is in some other directry, i.e. /tmp/.

Isn't the inode value getting modified in some ways to point to the correct location / beginning of the data block on the hard disk? If the the physical location of the data would not change then we would not be able to free up space in our home directory. That means the mv operation is copying the file into some other location. In other words, it is also performing the cp operation first and then deleting the file from its original location, my home directory in the case above.

However, when a file is copied it's inode value changes. But the mv operation is retaining the same indoe value.

So, how to determine which operation - mv or cp - is more CPU-friendly or more efficient in terms of performance and time taken to perform the action?

Useless Note (You may not need to read this stuff if you are going to give your views): Those who may find the above discussion senseless should not blame me. I have been asked this question in an interview. Whatever I have stated above, I told the interviewer. But I was not sure of what subtlety he had in his mind when he asked me the question.

Last edited by devUnix; 10-13-2010 at 09:20 PM.
Old 10-13-2010, 09:22 PM   #2
Senior Member
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,817

Rep: Reputation: 610Reputation: 610Reputation: 610Reputation: 610Reputation: 610Reputation: 610
Are the source and destination on the same partition? mv will be faster all of the time because it is just changing metadata. cp actually has to copy data, and disks are sloooow.

If the src and dest are on different partitions, I imagine there will be no practical difference in time between cp and mv


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing files and copying differences gregmcc Linux - Newbie 7 04-23-2009 12:54 PM
Copying directories of files with differences devnull0 Linux - General 4 04-21-2008 01:09 PM
drastic speed differences on copying on hard disks lsu420luv Linux - Hardware 2 04-17-2006 10:50 AM
Performing root operations in X such as moving files... pujolasdf Linux - Software 3 03-26-2005 11:55 AM
copying/moving stalls when moving a lot of data to a usb stick =X= Linux - Hardware 10 07-30-2004 05:29 AM

All times are GMT -5. The time now is 01:52 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration