mv

mv is a file management utility used to move or rename files and directories. It is a versatile tool that allows you to rename, move, or even merge files and directories.

Basic Syntax

mv [options] source destination

Here, source specifies the file or directory to be moved, and destination specifies the new name or location of the file or directory. If destination is a directory, the source file or directory is moved into the directory.

Commonly Used Options

  • -i: This prompts the user for confirmation before overwriting an existing file.
  • -f: This forces the move of a file or directory without prompting for confirmation, and overwrites an existing file with the same name in the destination directory.
  • -v: This displays the progress of the move operation, including the source and destination files or directories.

Useful Examples

  • mv file1.txt file2.txt: This renames file1.txt to file2.txt.
  • mv file.txt /home/user/directory: This moves file.txt to the /home/user/directory directory.
  • mv file.txt dir/: This moves file.txt into the dir directory.
  • mv file.txt dir/file2.txt: This renames file.txt to file2.txt and moves it into the dir directory.
  • mv -i file.txt dir/file.txt: This moves file.txt into the dir directory and prompts the user for confirmation if a file with the same name already exists in the destination directory.
  • mv -f file.txt dir/file.txt: This moves file.txt into the dir directory and overwrites any existing file with the same name in the destination directory without prompting for confirmation.
  • mv -v file.txt dir/file.txt: This moves file.txt into the dir directory and displays the progress of the move operation.

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments

  1. […] Once installed, let’s first allow TCP traffic over your SSH port so that you don’t get locked out of…

  2. […] have the option to choose between Password and SSH key selection. Learn more about SSH keys here. It’s recommended…