Rename Files and Folders


mv

As you'll soon see, however, mv does something more than move, something that might seem a bit counterintuitive, but which makes perfect sense after you think about it a moment.

At this point, it's a good idea to introduce the other cool feature of mv. Yes, mv moves filesthat's its name, after allbut it also renames files. If you move a file, you have to give it a target name. There's no rule that the target name has to be the same as the source name, so shell users since time immemorial have relied on the mv command to rename files and directories.

$ pwd /home/scott/libby/by_pool $ ls -F libby_by_pool_02.jpg liebermans/ $ mv liebermans/ lieberman_pool/ $ ls -F libby_by_pool_02.jpg lieberman_pool/ 


When moving a directory using cp, you had to specify the -R (or --recursive) option in order to copy the actual directory itself. Not so with mv, which, as you can see in the previous example, happily moves or renames directories without the need for any extra option at all, a nice change from cp.

Caution

You need to know a very important, and unfortunately easy to overlook, detail about mv. If you are moving a soft link that points to a directory, you need to be extremely careful about what you type. Let's say you have a soft link named dogs in your home directory that points to /home/scott/pictures/dogs, and you want to move the link into the /home/scott/libby subdirectory. This command moves just the soft link:

$ mv dogs ~/libby 


This command, however, moves the directory to which the soft link points:

$ mv dogs/ ~/libby 


What was the difference? A simple forward slash at the end of the soft link. No forward slash and you're moving the soft link itself, and just the link; include a forward slash and you're moving the directory to which the soft link is designed to point, not the soft link. Be careful!




Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net