mv [ -i | -f ] SourceFile TargetFile
mv [ -i | -f ] SourceFile ... TargetDirectory
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. If both the -f and -i flags are specified in combination, the last flag specified takes precedence.
The mv command moves files and directories from one directory to another or renames a file or directory. If you move a file or directory to a new directory, it retains the base file name. When you move a file, all links to other files remain intact, except when you move it to a different file system. When you move a directory into an existing directory, the directory and its contents are added under the existing directory.
When you use the mv command to rename a file or directory, the TargetDirectory parameter can specify either a new file name or a new directory path name.
If moving the file would overwrite an existing file that does not have write-permission set and if standard input is a workstation, the mv command displays the file-permission code and reads a line from standard input. If that line begins with a y or the locale's equivalent of a y, the mv command moves the file. If the response is anything other than a y, the mv command does nothing to that file and continues with the next specified file. The file-permission code displayed may not fully represent the access permission if the TargetFile is associated with an ACL. When the parent directory of the SourceFile is writable and has the sticky bit set, one or more of the following conditions are true:
You can use the mv command to move files within the same file system or between file systems. Whether you are working in one file system or across file systems, the mv command copies the file to the target and deletes the original file. The mv command preserves in the new file the time of the most recent data modification, the time of the most recent access, the user ID, the group ID, and the file mode of the original file. For symbolic links, the mv command preserves only the owner and group of the link itself.
If it is unable to preserve the owner and group ID, the mv command clears S_ISUID and S_ISGID bits in the target. The mv command prints a diagnostic message to stderr if it is unable to clear these bits, though the exit code is not affected.
The mv command modifies either the source file or the destination path if the command is prematurely terminated.
Note: The mv command supports the -- (dash, dash) parameter as a delimiter that indicates the end of the flags.
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. If both the -f and -i flags are specified in combination, the last flag specified takes precedence.
mv appendix apndx.a
This command renames appendix to apndx.a. If a file named apndx.a already exists, its old contents are replaced with those of appendix.
mv book manual
This command moves all files and directories under book to the directory named manual, if manual exists. Otherwise, the directory book is renamed manual.
mv intro manual/chap1
This command moves intro to manual/chap1. The name intro is removed from the current directory, and the same file appears as chap1 in the directory manual.
mv chap3 manual
This command moves chap3 to manual/chap3
Note: Examples 1 and 3 name two files, example 2 names two existing directories, and example 4 names a file and a directory.
mv chap4 jim/chap5 /home/manual
This command moves the chap4 file to the /home/manual/chap4 file directory and the jim/chap5 file to the /home/manual/chap5 file.
mv manual/* .
This command moves all files in the manual directory into the current directory . (period), retaining the names they had in manual. This move also empties manual. You must type a space between the asterisk and the period.
Note: Pattern-matching characters expand names of existing files only. For example, the command mv intro man*/chap1 does not work if the file manual/chap1 does not exist.
0 | All input files were moved successfully. |
>0 | An error occurred. |
/usr/bin/mv | Contains the mv command. |
The chmod command, ln command, rm command.
The rename subroutine.
Files Overview in the AIX 5L Version 5.1 System User's Guide: Operating System and Devices.
Directory Overview in AIX 5L Version 5.1 System User's Guide: Operating System and Devices.
Input and Output Redirection Overview in AIX 5L Version 5.1 System User's Guide: Operating System and Devices.