| Files and directories can be renamed and
moved using the same multipurpose mv
(move) command. There is no rename command in UNIX. The command format
below shows the syntax to rename a file in the same directory. Note
that the interactive option is available with the mv
command. The mv
-i
option prompts for confirmation whenever the move would overwrite an
existing target file. An answer of y means that the move should
proceed. Any other answer prevents mv
from overwriting the target file. The mv
command changes the name of the original file, whereas the cp
command copies a file and gives it a new name leaving the original
file intact.
Renaming a File in the Current
Directory
If you wish to RENAME a file to another file name within the same
directory, use the format in Figure .
The format in Figure
changes the name of the source (old File Name) to a target file name
(new File Name) in the same directory. This version can be thought of
as moving from OLD to NEW in the same directory. Figure
shows renaming a file using this format.
Moving a File to another Directory
If you wish to MOVE a file to a different directory, use the format in
Figure .
The format in Figure
moves the source file(s) to a new target directory. You can add a
slash and a file name after the destination directory to give the file
a different name if desired. It moves the source (what to move) to a
target directory name (where to move). This version can be thought of
as moving from WHAT to WHERE in the same directory. Figure
shows moving a file to another directory using the format in Figure .
Note that the example shows moving the brands file from the coffees
subdirectory to the home directory using the tilde (~) shortcut.
 |
|
Interactive Media Activity
(Flash, 95 kB) |
| |
Renaming
and Moving Files
In this media activity, you are logged in as user2 and your current working directory is: /home/user2/dir2. Refer to the Class File Tree Structure by clicking the 'tree' button located on the Menu Bar and type the commands that would accomplish the requested objectives.
Note: Be sure to press enter after each one. Click on step 1 to begin.
|
|
|
|
|