What is the mv Command in Linux?
The mv
command stands for move. At its core, mv
does what its name suggests: it relocats files or directories from one location to another. However, its utility extends far beyond mere relocation, it can do reorganizing, renaming and even merging data within the file system.
Basic syntax
mv [options] [source] [destination]
Rename a file or directory:
mv file.txt new-file-name.txt
# or
mv directory new-directory-name
Move a file or directory:
mv file.txt directory/
Rename a file and move to a directory:
mv file.txt diectory/new-file-name.txt
Options
Option | Description |
---|---|
-i, —interactive | Prompts before overwriting existing files. |
-f, —force | Overrides any existing files at the destination without prompting for confirmation. |
-n, —no-clobber | Prevents mv from overwriting existing files. |
-u, —update | Moves only when the source file is newer than the destination file or when the destination file is missing. |
-v, —verbose | Provides detailed feedback on the actions performed by mv . |
-b, —backup | Creates a backup of existing destination files. |
-S, —suffix | Specifies the suffix to be appended to backup filenames, in conjunction with the -b option. |
Additionally, you can explore more by using the commands:
mv --help
# or
man mv
Thank you!
Thank you for your time and for reading this!