8.4.23 mv command (moves files or directories)
Syntax
mv [-f] [-i] [-u]source destination mv [-f] [-i] [-u]source ... destination-directory
Description
This command moves files or directories. It can also change the names of files or directories.
Arguments
-f
- --force
-
This command overwrites the path without verifying the path. This command is ignored if this command is specified before the -i option.
-i
- --interactive
-
This command enables you to confirm overwriting. If you reply y or Y from the standard input, the path is overwritten. This command is ignored if this command is specified before the -f option.
-u
- --update
-
If the destination file already exists and the last modification date and time are the same as or later than those of the source while you attempt to move a file other than directory, file is not moved. The last modified date and time of a file is determined upon rounding off values smaller than a second.
- source
-
This command specifies the name of the path to be moved. Multiple path names can be specified for the source.
- destination
-
This command specifies the name of the path of the destination. If you specify the path name for source and destination, you can change the file name or directory name.
- destination-directory
-
This command specifies the directory of destination. If you specify multiple path names for the source, you can move multiple files and directories.
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 8.4.21 ls command (lists the contents of files or directories).
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 Windows, if a file that has the same name as the file you are attempting to move already exists in the destination, depending on the status of the Windows environment in which the command is executed, the error Permission denied might be output.
-
In Windows, when moving files to another drive, if you set the read-only attribute to the files to be moved, a 1,550-millisecond delay occurs when each file is moved. Therefore, before using a wildcard to specify multiple files or moving multiple files in a directory, remove the read-only attribute first.
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
-
If the file does not move with the specification of the -u option because the destination is new (including the case that the destination is the same), no error occurs and this command normally terminates.
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 [-fiu] source target mv [-fiu] 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