10 Oct 2008

Difference between cp and mv commands in UNIX

CEans,

I've a simple query related to UNIX. What is the difference between cp and mv commands in UNIX?

Are these commands similar to copy and 'cut' command operations that we do in Windows? Are there any other differences?
Prasad Ajinkya

Prasad Ajinkya

Branch Unspecified
10 Oct 2008
Biggie,

The cp command will copy one file to the another destination without deleting the original. The mv command will move the file to the other destination (copy the file to the destination and then delete the original). Same concept behind the difference of "Copy and Paste" v/s "Cut and Paste".

It gets more complex, when you consider these commands with the folders instead of files.
10 Oct 2008
Yep, I'm aware of that difference. I want to know if there's more to cp & mv commands, while working with files?

Thanks for the response.
Prasad Ajinkya

Prasad Ajinkya

Branch Unspecified
10 Oct 2008
Yes, try man pages for detailed dope. But you start seeing the nuances when you do commands like
cp -r /home/kidakaka/mycrap/* /newfolder/newfolder/newfolder/newfolder
mv -r /home/kidakaka /home/prasad

Or in a different way ... eg. using mv as a renaming tool
10 Oct 2008
I see! Thanks a ton for your response.
sriramchandrk

sriramchandrk

Branch Unspecified
13 Oct 2008
Hi,

You need to know about unix file system.

We should know the data structure in it i.e., superblock, inodes, databolocks.

mv and cp are just operations on them!

Its long time since i read it, i have totally forgot, i can just give a link to the text book!

Design of Unix Operating System - Maurice J. Bach

Will read today and let you know the right answer.

Thanks & Regards
Sriram
13 Oct 2008
That will be great. I only want to know if there's much to mv and cp than 'cut' and 'paste'.

Share this content on your social channels -

Only logged in users can reply.