Mv

From Unix SME

Description

  The 'mv' command allows for the moving of files and directories from one location to another. This is fundamental for file management, organization and effective navigation of files. This command also allows for the renaming of files and directories. 


Syntax and Structure

Movement-
  mv [options] [source_file] [Destination_file]
Renaming-
  mv [options] oldname newname


Use Case

  The 'mv' command is used for two purposes: the relocation of files and directories to a new location and the renaming of existing files.

Examples

Rename files

  [user@host ~]$ mv oldfile.txt newfile.txt

Move File to Different Directory

  [user@host ~]$ mv file.txt /misc/to/temp/

Move Multiple Files

  [user@host ~]$ mv file1.txt file2.txt /bin/to/ect/

Rename Directory

  [user@host ~]$ mv old_directory new_directory

Move Directory to Another Directory

  [user@host ~]$ mv /path/to/source_directory /path/to/destination_directory/

Wildcard Move Multiple Files

  [user@host ~]$ mv *.txt /temp/to/bin/

Move Files Interactively(asks for confirmation to overwrite

  [user@host ~]$ mv -i duplicatefile.txt /file1/to/file2

Verbose Movement of Files

  [user@host ~]$ mv -v file.txt /bin/to/dev/

Move Files Forcefully

  [user@host ~]$ mv -f main.txt /source/to/temp/

Disable overwriting destination files

  [user@host ~]$ mv -n main.txt /source/to/temp/

Update destination file

  [user@host ~]$ mv -u main.txt /source/to/temp/

Move All Files in a Directory

  [user@host ~]$ mv /path/to/source/* /path/to/destination/

Create a backup of the destination file

  [user@host ~]$ mv --backup main.txt /source/to/temp/