mv command (moves files or directories)
- Organization of this page
Format
mv [-f] [-i] source destination mv [-f] [-i] source ... destination-directory
Description
This command moves files or directories. It can also be used to change the name of a file or directory.
Arguments
- -f
-
Specifies that path overwriting is to be performed without requesting confirmation. This option is ignored if it is specified before the -i option.
- -i
-
Specifies that confirmation is to be requested before overwriting is performed. Overwriting will be performed only if the reply y or Y is read from the standard input. This option is ignored if it is specified before the -f option.
- source
-
Specifies the path name to be moved. Multiple path names can be specified.
- destination
-
Specifies the destination path name. You can also change the name of a file or directory by specifying a path name for both source and destination.
- destination-directory
-
Specifies the destination directory name. You can move more than one file or directory by specifying multiple path names in source.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
1 or greater |
Error termination |
Notes
-
If the -i and -f options are both specified, the one specified last takes effect.
-
In Windows, when a file or directory is overwritten, access permissions other than the owner's are not displayed.
For details about the permissions that are displayed, see ls command (lists the contents of files or directories).
-
In Windows, symbolic links are not supported.
-
In Windows, group and mode are not preserved.
-
In Windows, the destination file name will be created using the file name specified in the source. However, uppercase letters in the file name will be replaced with lowercase letters. For example, if the name of the file to be moved is A.txt and you execute mv a.txt tmpdir, the name of the file in tmpdir will be a.txt.
-
In Windows, file input and output are performed in the binary mode. No conversion of end-of-line codes is performed.
-
In UNIX, when the mv command is used to move a file or directory and all the following conditions are satisfied, the user who executes the mv command becomes the owner of the file or directory:
-
A general user executed the mv command.
-
The user executing the mv command is different from the owner of the source file.
-
The source and destination file systems are different.
In addition, the following information will not be inherited:
-
The access permission information set in the setuid and setgid bits of the source file
-
The access permission information set in the setuid, setgid, and sticky bits of the source directory
-
Usage examples
-
Specify the -i option to require confirmation before the destination file is overwritten.
C:\TEMP>%ADSH_OSCMD_DIR%\mv -i ..\dir1\file1.txt ..\dir1\file2.txt overwrite ..\dir1\file2.txt?
-
Display an option error message.
This message might vary depending on the platform on which the command is executed. The following shows an example in Windows:
C:\TEMP>%ADSH_OSCMD_DIR%\mv -w mv: illegal option -- w usage: mv [-fi] source target mv [-fi] source ... directory
-
Display an error message if a file does not exist.
C:\TEMP>%ADSH_OSCMD_DIR%\mv file3.txt file4.txt mv: file3.txt: No such file or directory