LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

mv

moves and renames files and directories

TLDR

Move a file to a directory
$ mv [source] [directory/]
copy
Rename a file
$ mv [oldname.txt] [newname.txt]
copy
Move multiple files to a directory
$ mv [file1] [file2] [directory/]
copy
Move with confirmation before overwrite
$ mv -i [source] [destination]
copy
Don't overwrite existing files
$ mv -n [source] [destination]
copy
Move and show what's being done
$ mv -v [source] [destination]
copy
Move with backup of existing destination
$ mv --backup=numbered [source] [destination]
copy

SYNOPSIS

mv [options] source... destination

DESCRIPTION

mv moves and renames files and directories. When the source and destination are on the same filesystem, it performs an atomic rename. When moving across filesystems, it copies the data and then removes the original.Renaming is simply moving a file within the same directory. Moving a file into a directory places it inside that directory with the same basename.If multiple sources are given, the last argument must be a directory and all sources are moved into it.

PARAMETERS

-i, --interactive

Prompt before overwriting an existing file.
-f, --force
Do not prompt before overwriting. Overrides -i and -n.
-n, --no-clobber
Do not overwrite an existing file. Overrides -i and -f.
-v, --verbose
Print the name of each file being moved.
-u, --update
Move only when the source is newer than the destination or the destination does not exist.
--backup[=CONTROL]
Make a backup of each existing destination file. CONTROL can be numbered, existing, simple, or none.
-S, --suffix SUFFIX
Override the usual backup suffix (default ~).
-t, --target-directory DIRECTORY
Move all sources into the specified directory.
-T, --no-target-directory
Treat destination as a normal file, not a directory.

CAVEATS

mv overwrites existing destination files by default without warning. Use -i or -n to prevent accidental data loss. When moving across filesystems, the operation is not atomic: the file is copied first, then the original is deleted.

HISTORY

mv is one of the original Unix commands, present since Version 1 AT&T Unix in 1971.

SEE ALSO

cp(1), rm(1), rename(1), rsync(1), install(1)

Copied to clipboard
Kai