LinuxCommandLibrary

mv

Move (rename) files or directories

TLDR

Rename a file or directory when the target is not an existing directory

$ mv [path/to/source] [path/to/target]
copy

Move a file or directory into an existing directory
$ mv [path/to/source] [path/to/existing_directory]
copy

Move multiple files into an existing directory, keeping the filenames unchanged
$ mv [path/to/source1 path/to/source2 ...] [path/to/existing_directory]
copy

Do not prompt for confirmation before overwriting existing files
$ mv [[-f|--force]] [path/to/source] [path/to/target]
copy

Prompt for confirmation interactively before overwriting existing files, regardless of file permissions
$ mv [[-i|--interactive]] [path/to/source] [path/to/target]
copy

Do not overwrite existing files at the target
$ mv [[-n|--no-clobber]] [path/to/source] [path/to/target]
copy

Move files in verbose mode, showing files after they are moved
$ mv [[-v|--verbose]] [path/to/source] [path/to/target]
copy

Specify target directory so that you can use external tools to gather movable files
$ [find /var/log -type f -name '*.log' -print0] | [xargs -0] mv [[-t|--target-directory]] [path/to/target_directory]
copy

SYNOPSIS

mv [options] source... destination

PARAMETERS

-b, --backup
    Make backup of existing destination

-f, --force
    Don't prompt before overwriting

-i, --interactive
    Prompt before overwriting

-n, --no-clobber
    Don't overwrite existing files

-t, --target-directory=DIR
    Move all sources to directory

-u, --update
    Move only when source is newer

-v, --verbose
    Explain what is being done

--strip-trailing-slashes
    Remove trailing slashes from source

-T, --no-target-directory
    Treat destination as normal file

DESCRIPTION

mv moves or renames files and directories. When moving within the same filesystem, it simply renames the file (changing directory entries). When moving across filesystems, it copies the data and then removes the original.

CAVEATS

Cross-filesystem moves are slower (copy + delete). Moving to existing directory places source inside it. Permissions may change on cross-filesystem moves.

SEE ALSO

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

Copied to clipboard