Skip to content

Latest commit

 

History

History
46 lines (32 loc) · 2.08 KB

032-the-mv-command.md

File metadata and controls

46 lines (32 loc) · 2.08 KB

The mv command

The mv command lets you move one or more files or directories from one place to another in a file system like UNIX. It can be used for two distinct functions:

  • To rename a file or folder.
  • To move a group of files to a different directory.

Note: No additional space is consumed on a disk during renaming, and the mv command doesn't provide a prompt for confirmation

Syntax:

mv [options] source (file or directory)  destination

Examples:

  1. To rename a file called old_name.txt:
mv old_name.txt new_name.txt
  1. To move a file called essay.txt from current directory to a directory called assignments and rename it essay1.txt:
mv essay.txt assignments/essay1.txt
  1. To move a file called essay.txt from current directory to a directory called assignments without renaming it
mv essay.txt assignments

Additional Flags and their Functionalities:

Short Flag Long Flag Description
-f --force Force move by overwriting destination file without prompt
-i --interactive Interactive prompt before overwrite
-u --update Move only when the source file is newer than the destination file or when the destination file is missing
-n --no-clobber Do not overwrite an existing file
-v --verbose Print source and destination files
-b --backup Create a Backup of Existing Destination File