Skip to content

Latest commit

 

History

History
85 lines (57 loc) · 1.46 KB

mv.md

File metadata and controls

85 lines (57 loc) · 1.46 KB

mv

move (rename) files


References

  • man mv

Quickstart

mv original_name new_name           # rename file / dir

mv src_file /path/to/dest_file      # file to file path
mv src_file destination_dir/        # file to dir

mv -t dest_dir/ src_file1 src_file2 # files to dir path

Synopsis

mv [OPTION]... [-T] SOURCE DEST
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCE...

Options

Interact

If you specify more than one of -i, -f, -n, only the final one takes effect.

  • -f, --force do not prompt before overwriting
  • -i, --interactive prompt before overwriting
  • -n, --no-clobber do not overwrite an existing file

Common

  • -t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY
  • -u, --update move only when the SOURCE file is newer than the destination file or when the destination file is missing

Others

  • --backup[=CONTROL] make a backup of each existing destination file
  • -b like --backup but does not accept an argument

See man mv for more.

Usage

Move

Default

mv <source_file> <destination_file>
# e.g.
mv tmp.log /tmp/tmp.log
mv <source_file> <destination_dir>
# e.g.
mv tmp.log /tmp/
mv *.log logs/

Files to Directory

mv -t <destination_dir> <source_file1> <source_file2> ……
# e.g.
mv -t logs/ info.log warn.log

Rename

mv <source_file> <new_file_name>
# e.g.
mv tmp.log info.log