mv (host)
Move files (POSIX)
Syntax:
mv [-f|-i] [-v|-V] source_file target_file
mv [-f|-i] [-v|-V] source_file... target_dir
Runs on:
Microsoft WindowsOptions:
- -f
- Force an overwrite; don't prompt for confirmation if the destination path exists. Overwrite even read-only files.
- -i
- Run interactively; write a prompt to the standard error output before moving any file that would overwrite an existing file. If confirmation is received, overwrite the existing file. Otherwise, go on to the next file.
- -V
- (QNX OS extension) Be very verbose.
- -v
- (QNX OS extension) Be verbose.
- source_file
- The pathname of a file or directory to be moved.
- target_file
- The new pathname of the file or directory to be moved.
- target_dir
- The pathname of an existing directory that the source file is to move to.
Description:
The mv command has two syntax forms:
- mv [-f|-i] [-v|-V] source_file target_file
- The mv utility moves source_file to the destination specified by target_file. This first syntax form is assumed when the final operand you specify doesn't name an existing directory.
- mv [-f|-i] [-v|-V] source_file... target_dir
- The mv utility moves each source_file file to a
destination file in the directory named by target_dir. The
destination's filename under the target directory is the same as its basename (final
path component).
For example:
moves dir/dir/myfile to existingdir/myfile.mv dir/dir/myfile /existingdir
This second syntax form is assumed when either the destination names an existing directory, or when more than one source file is specified.
The mv utility asks you for confirmation if the following conditions are met:
- you haven't specified the -f option
- you lack write permission
- the standard input is a terminal
Upon receiving confirmation, mv overwrites the target file. It can do this only if you own the file or you're a 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.
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 is 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 aren't copied. Since the copy isn't 100% successful, the original source_file isn't removed.
Examples:
In the current directory, rename the file orange to banana.
mv orange banana
Exit status:
- 0
- All input files were moved successfully.
- >0
- An error occurred.
Caveats:
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 isn't modified.
When the source_file and target_file are on different filesystems (i.e., not on the same mounted partition), mv spawns the cp utility to copy the file(s), and if the cp succeeds, spawns the rm utility to remove the originals.