134
11.8.2 Moving Files
To move files, use the mv command. It is similar to the cp command, except that with mv the file is
physically moved from one place to another, instead of being duplicated, as with cp. For more about
mv, see the mv man page (type man mv).
Common options for mv include the following:
•
-i — interactive. This will prompt you if the file you have selected will overwrite an existing file
in the destination directory. This is a good option, because like the -i option for cp, you will be
given the chance to make sure you want to replace an existing file.
•
-f — force. Overrides the interactive mode and moves without prompting. Unless you know
what you are doing, this option is dangerous; be very careful about using it until you become more
comfortable with your system.
•
-v — verbose. Shows a list of the files being moved.
If you want to move a file out of your home directory and into another directory, type the following
(you will need to be in your home directory):
mv sneakers.txt tigger
Alternatively, the same command using absolute pathnames looks like mv sneakers.txt
/home/newuser /home/newuser/tigger.
11.8.3 Renaming Files
Actually, we have already covered half of renaming, because when you copy or move files, you can
also rename.
To copy the file sneakers.txt from your login directory to the tigger subdirectory, just type:
cp sneakers.txt tigger
To copy and rename that file from sneakers.txt to piglet.txt, type:
cp sneakers.txt tigger/piglet.txt
To move and rename the file, just substitute mv for cp in the above example.
If you cd to tigger and then type ls, you will see the file piglet.txt.
If you just want to rename the file and keep its location, just mv in your current directory:
mv sneakers.txt piglet.txt
Chapter 11:Managing Files and Directories
Need help?
Do you have a question about the LINUX 7.2 and is the answer not in the manual?
Questions and answers