This subchapter looks at mv, a UNIX (and Linux) command.
Teach Yourself UNIX/Linux System Administration and Shell Programming
table of contents
If you like the idea of this project,
then please donate some money.
more information on donating
This subchapter looks at mv, a UNIX (and Linux) command.
mv is used to move or rename a file.
Use the mv command to rename a file. This example assumes you created the names and saved_name files in the quick tour subchapter.
$ mv saved_named old_names
$
Notice that the shell is once again silent with success. You can use the ls command to confirm that the rename really was made.
$ ls
Desktop Movies Send registration
Documents Music Sites
Downloads Pictures names
Library Public old_names
$
A common error is the source file not existing (often because of a typing or speling error).
Use the -i option to have an interactive confirmation before overwriting an existing file. Note that this does not seem to work on Mac OS X Mountain Lion.
$ mv -i names saved_names
overwrite saved_names? (y/n [n]) n
not overwritten
$
Use the -f option to force rename (mv) to overwrite any file with a matching name. This is the same as the default action of the mv command.
$ mv -f names saved_names
Use the -n option to prevent rename (mv) from overwriting any file with a matching name.
$ mv -n names saved_names
mv is the UNIX equivalent of the MS-DOS or PC-DOS command REN. You can add the PC-DOS equivalent to your shell session with the alias command. To make the change permanent, add the following line to the .bashrc file in your home directory.
$ alias REN="mv"
On November 8, 2010, Ramesh Natarajan named this the number 29 most frequently used UNIX/Linux command at this web page 50 Most Frequently Used UNIX / Linux Commands (With Examples).
In June 2009, Ken Milberg named this command as one of the Top 50 universal UNIX commands at this web page Top 50 Universal INIX commands. Note that this web page requires agreeing to be spammed before you can read it.
Coding example: I am making heavily documented and explained open source code for a method to play music for free almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).
View music player in action: www.musicinpublic.com/.
Create your own copy from the original source code/ (presented for learning programming).
return to table of contents
free downloadable college text book
free downloadable system administrator and shell programming book
Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.
Teach Yourself UNIX/Linux System Administration and Shell Programming
Building a free downloadable text book on computer programming for university, college, community college, and high school classes in computer programming.
If you like the idea of this project,
then please donate some money.
send donations to:
Milo
PO Box 1361
Tustin, California 92781
Supporting the entire project:
If you have a business or organization that can support the entire cost of this project, please contact Pr Ntr Kmt (my church)
Some or all of the material on this web page appears in the
free downloadable college text book on computer programming.
This web site handcrafted on Macintosh computers using Tom Benders Tex-Edit Plus and served using FreeBSD .
UNIX used as a generic term unless specifically used as a trademark (such as in the phrase UNIX certified). UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company Ltd.
Names and logos of various OSs are trademarks of their respective owners.
Copyright © 2012, 2013 Milo
Created: February 8, 2012
Last Updated: August 21, 2013
return to table of contents
free downloadable college text book
free downloadable system administrator and shell programming book