mv or move Command Purpose Moves files. Syntax To Move Files to a Directory Maintaining Original File Names { mv | move } [ -i ] [ -f ] [ -- ] { File ... | Directory ... } Directory To Move and Rename a File or Directory { mv | move } [ -i ] [ -f ] [ -- ] { File | Directory } NewName Description Warning: The mv command can overwrite many existing files unless you specify the -i flag. The -i flag prompts you to confirm be- fore it overwrites a file. If both the -f and -i flags are specified in combination, the last flag specified takes pre- cedence. The mv (move) command moves files and directories from one direc- tory 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 in- tact, 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 NewName 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 lo- cale'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. 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 modif- ication, the time of the most recent access, the user ID, the group ID, and the file mode of the original file. Flags Warning: The mv command can overwrite many existing files unless you specify the -i flag. The -i flag prompts you to confirm be- fore it overwrites a file. If both the -f and -i flags are specified in combination, the last flag specified takes pre- cedence. -f Does not prompt you before overwriting an existing file. -i Prompts you before moving a file or directory to an existing path name by displaying the name of the file followed by a ques- tion mark. If you answer with a line starting with y or the lo- cale's equivalent of a y, the move continues. Any other reply prevents the move from occurring. -- Interprets all the following arguments as file names. This allows you to create file names starting with a minus sign. Examples Warning: The mv command can overwrite many existing files unless you specify the -i flag. The -i flag prompts you to confirm be- fore it overwrites a file. If both the -f and -i flags are specified in combination, the last flag specified takes pre- cedence. 1. To rename a file, enter: mv appendix apndx.a This renames appendix to apndx.a. If a file named apndx.a already exists, its old contents are replaced with those of appendix. 2. To move a directory, enter: mv book manual This moves all files and directories under book to the directory named manual, if manual exists. Otherwise, the directory book is renamed to manual. 3. To move a file to another directory and give it a new name, enter: mv intro manual/chap1 This 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. 4. To move a file to another directory, keeping the same name, enter: mv chap3 manual This moves chap3 to manual/chap3 Note: Examples 1 and 3 name two files, example 2 names two exist- ing directories, and example 4 names a file and a directory. 5. To move several files into another directory, enter: mv chap4 jim/chap5 /home/manual This moves the chap4 file to the /home/manual/chap4 file directory and the jim/chap5 file to the /home/manual/chap5 file. 6. To use the mv command with pattern-matching characters, enter: mv manual/* . This 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. Exit Status 0 All input files were moved successfully. >0 An error occurred. Implementation Specifics This command is part of Base Operating System (BOS) Runtime. Files /usr/bin/mv Contains the mv command. /usr/bin/move Contains the move command. Related Information Files Overview in AIX Version 3.2 System User's Guide: Base and Devices. Directory Overview in AIX Version 3.2 System User's Guide: Base and Devices. Input and Output Redirection Overview in AIX Version 3.2 System User's Guide: Base and Devices. The chmod command, ln command, rm command. The rename subroutine.