… and to move around stuff!

Object moving, is like a normal copy, but the source of the object gets deleted, or in special situations, renamed. To be a little bit more technical, when you issue the cp command to copy a file for example, this creates a completely new file system entry, data and inode. On the other hand the mv command simply changes where the file is located in the directory structure, or if you make a mv on a same directory, it simply changes the name of the object.
Main difference in mv command, to cp command, is the fact that you don’t have to issue the -r/-R flag, because cp itself by nature, is recursive. This means when you move a directory, it moves everything inside also.

When you do a move, the first thing that is checked, is if the target already exists on destination. If so, it will ask you if you want to overwrite; you can had the -f (force) flag, if you are really sure that this is what you intended.

In the opposite of -f is -u, which prevents you to inadvertently overwrite newer target files or directories, preserving the newest copy of what you are moving.

Like you have learned in copy article, moving follows some rules, whereas you do a move on a directory contents, if you don’t specify exactly what you want, you get the wrong results. Remember to use the * to really say that you want the contents, not the all directory itself (and by definition also his contents)

One thing to end this mv article. They don’t tell you this (i call it the Rename Conspiration), but if you do a mv on the same directory, you are issuing a rename. I know, it may sound simple, but newcomers get confused with this simple concept.

Go on, enjoy your copy and moving, and don’t forget to surf the man pages entrys, to learn more exciting (ye right) things.

LINKS: man mv

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

0 comments ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment

Creative Commons License
dbugs.org by Marco Garcês is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License.