Move files (POSIX)
mv [-f|-i] [-v|-V] source_file target_file mv [-f|-i] [-v|-V] source_file... target_dir
QNX Neutrino, Microsoft Windows
- Force an overwrite; don't prompt for confirmation if the destination path exists. Overwrite even read-only files.
- 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.
- (QNX Neutrino extension) Be very verbose.
- (QNX Neutrino extension) Be verbose.
- The pathname of a file or directory to be moved.
- The new pathname of the file or directory to be moved.
- The pathname of an existing directory that the source file is to move to.
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).
mv dir/dir/myfile /existingdirmoves 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:
- 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.
In the current directory, rename the file orange to banana.
mv orange banana
- All input files were moved successfully.
- An error occurred.
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), the mv utility spawns the cp utility to copy the file(s), and if the cp succeeds, spawns the rm utility to remove the originals.