Move files (POSIX)
mv [-f|-i] [-v|-V] source_file target_file mv [-f|-i] [-v|-V] source_file... target_dir
The mv utility moves the file named by the source_file operand to the destination specified by the target_file operand. This first syntax form is assumed when the final operand you specify doesn't name an existing directory.
For each source_file, the mv utility moves the file to a destination file in the directory named by the target_dir operand. The destination's filename under the target directory will be the same as its basename (final path component).
For example:
mv dir/dir/myfile /existingdirwill move dir/dir/myfile to existingdir/myfile.
This second syntax form is assumed when either the destination names an existing directory, or when more than one source file is specified.
By default, mv overwrites an existing file without warning or confirmation whenever you have write permission on the file. |
The mv utility asks you for confirmation if the following conditions are met:
Upon receiving confirmation, mv overwrites the target file. It can do this only if the user owns the file or is the superuser.
If you want mv to request confirmation before overwriting any file, specify the -i (interactive) option. If you want mv to overwrite whenever possible without asking for confirmation, specify the -f (force) option.
In the current directory, rename the file orange to banana.
mv orange banana
As long as the input files specified by each source_file are on the same device as the target, the source_file operand can be of any file type. If the source and target reside on different devices, the source_file will be copied to the target and then removed. If the source_file is a directory, this means that any FIFO or character special files under the original directory will not be copied. Since the copy will not be 100% successful, the original source_file will not be removed.
If the copying of a directory is prematurely terminated by a signal or error, mv may leave a partial copy of the directory at the destination. In this case, the directory tree at source_file will not have been modified.
When the source_file and target_file are on different filesystems (i.e. not on the same mounted partition), the mv utility will spawn the cp utility to copy the file(s), and if the cp succeeds, will spawn the rm utility to remove the originals.