Exploring mv - Linux Commands

| 4 min read

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

OptionDescription
-i, —interactivePrompts before overwriting existing files.
-f, —forceOverrides any existing files at the destination without prompting for confirmation.
-n, —no-clobberPrevents mv from overwriting existing files.
-u, —updateMoves only when the source file is newer than the destination file or when the destination file is missing.
-v, —verboseProvides detailed feedback on the actions performed by mv.
-b, —backupCreates a backup of existing destination files.
-S, —suffixSpecifies 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!