[Previous] [Contents] [Next]

mv

Move files (POSIX)

Syntax:

mv [-f|-i] [-v|-V] source_file target_file

mv [-f|-i] [-v|-V] source_file... target_dir

Options:

-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 extension) Be verbose.
-V
(QNX extension) Be very 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:

First syntax form:
mv [-f|-i] [-v|-V] source_file target_file

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.

Second syntax form:
mv [-f|-i] [-v|-V] source_file... target_dir

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 /existingdir
will 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.


Note: 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.

Examples:

In the current directory, rename the file orange to banana.

    mv orange banana

Files:

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.

Exit status:

0
All input files were moved successfully.
>0
An error occurred.

Errors:

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.

Caveats:

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.

See also:

cp, pax, rm


[Previous] [Contents] [Next]