Jump to content

mv

From RaySoft

mv is a shell command for renaming and moving files and directories. If both items are on the same file system, the command renames; otherwise items are copied to the destination and the old items are removed (more specifically unlinked). To move between two directories, the user must have write permission for both because the command modifies the content of both. For a rename, an item's timestamp is not modified.[1]

Documentation

Further information

Syntax

mv [PARAMETER ...] SRC [SRC ...] DST
mv [PARAMETER ...] -t DIR SRC [SRC ...]

Parameters

General
The following parameters can be used with all version of mv:
NOTE:
The BSD version only supports the short form (e.g. -f) of these parameters!
-f, --force
Do not prompt before overwriting.
-n, --no-clobber
Do not overwrite an existing file.
GNU
The following parameters can be used with the GNU version of mv:
--backup[=CONTROL]
Make a backup of each existing destination file.
The backup suffix is ~, unless set with --suffix or SIMPLE_BACKUP_SUFFIX. The version control method may be selected via the --backup option or through the VERSION_CONTROL environment variable. Here are the values:
none, off
Never make backups (even if --backup is given).
numbered, t
Make numbered backups.
existing, nil
Numbered if numbered backups exist, simple otherwise.
simple, never
Always make simple backups.
-b
Like --backup but does not accept an argument.
-t DIR, --target-directory=DIR
Move all SRC arguments into DIR.

Examples

Remove the file extension 'bak' for all files in the current directory
for file in *.bak; do
  mv --update "${file}" "${file%.bak}"
done
Change the file extension from 'htm' to 'html' for all files in the current directory
for file in *.htm; do
  mv --update "${file}" "${file/%.htm/.html}"
done

References

  1. Wikipedia contributors. "mv (Unix)." Wikipedia. https://en.wikipedia.org/wiki/Mv_(Unix) (accessed 19.08.2025)