mv

From RaySoft

mv is a Unix command that moves one or more files or directories from one place to another. Since it can "move" files from one filename to another, it is also used to rename files. Using mv requires the user to have write permission for the directories the file will move between. This is because mv changes the file's location by editing the file list of each directory.[1]

Documentation

Further information

Syntax

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

Parameters

--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.
-f, --force
Do not prompt before overwriting.
-t DIR, --target-directory=DIR
Move all SRC arguments into DIR.
-u, --update
Move only when the SOURCE file is newer than the destination file or when the destination file is missing.

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