Moving and renaming files (mv command)
Use the mv command to move files and directories from one directory to another or to rename a file or directory. If you move a file or directory to a new directory without specifying a new name, it retains its original name.
Attention: The mv command can overwrite
many existing files unless you specify the -i flag. The -i flag
prompts you to confirm before it overwrites a file. The -f flag does
not prompt you. If both the -f and -i flags are specified in
combination, the last flag specified takes precedence.
- Moving files with mv command
- The following are examples of how to use the mv command:
- To move a file to another directory and give it a new name, type the following:
This moves the intro file to the manual/chap1 directory. The name intro is removed from the current directory, and the same file appears as chap1 in the manual directory.mv intro manual/chap1
- To move a file to another directory, keeping the same name, type the following:
This moves chap3 to manual/chap3.mv chap3 manual
- To move a file to another directory and give it a new name, type the following:
- Renaming files with mv command
-
Use the mv command to change the name of a file without moving it to another directory.
To rename a file, type the following:
This renames the appendix file to apndx.a. If a file named apndx.a already exists, its old contents are replaced with those of the appendix file.mv appendix apndx.a
See the mv command in the Commands Reference, Volume 3 for the complete syntax.