Installation guide
130 Chapter 12. Managing Files and Directories
To copy a file, type the following command:
cp source destination
replacing source with the name of the file you want to copy, and destination with the
name of the directory where you want the file to go.
So, to copy the file sneakers.txt to the directory tigger/ in your home directory, move to your
home directory and type:
cp sneakers.txt tigger/
You can use both relative and absolute pathnames with cp. Our home directory is the parent of the
directory tigger; tigger is one directory down from our home directory.
Read the cp man page (man cp) for a full list of the options available with cp. Among the options
you can use with cp are the following:
• -i — interactive. Prompts you to confirm if the file is going to overwrite a file in your destination.
This is a handy option because it can help prevent you from making mistakes.
• -r — recursive. Rather than just copying all the specified files and directories, this will copy the
whole directory tree, subdirectories and all.
• -v — verbose. shows the progress of the files being copied.
Now that you have the file sneakers.txt in the tigger directory, use cp -i to copy the file again
to the same location.
[newuser@localhost newuser]$ cp -i sneakers.txt tigger
cp: overwrite ’tigger/sneakers.txt’?
To overwrite the file that is already there, press [Y] and then [Enter]. If you do not want to overwrite
the file, press [N] and [Enter].
12.4.3. Moving Files
To move files, use the mv command. 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 existing 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.