mv Command in Linux with Examples

Posted in

mv Command in Linux with Examples

Sangeeta Gulia
Last updated on April 23, 2024

    The Linux command is a piece of software that comes pre-installed on the Linux operating system. With only a few commands, you can swiftly perform a range of sophisticated and easy activities. These commands are executed using the Linux terminal. The terminal, like the Windows command prompt, is a command-line interface for interacting with the system. Commands in Linux are case-sensitive.

    Moving files from the source to the destination is a common task. We may need various configurations for moving files. In this article, we will be going through the mv command and all its available options.

    What is the mv command?

    The shorthand mv stands for "move". The mv command is a fundamental Linux command for moving files and directories from one location to another. It may also be used to rename files and folders. During renaming, no more disc space is used. All Linux distributions include the mv command by default. This command usually operates silently, which means there is no confirmation prompt. The syntax for this command is:

    $ mv option source destination

    What is secondary memory?

    Secondary memory is where long-term programs and data are stored. Hard disks and optical discs are common secondary storage technologies. In comparison to the main memory, the hard drive has a massive storage capacity. A computer's hard disc is normally housed within the casing. The hard drive is used to store programs and data for lengthy periods of time. On the hard disc, data and applications are arranged into files. A file is a name for a collection of data on a disc. The Linux operating system has a disk as the secondary storage.

    1. -i (Interactive)

    The - i option, similar to cp, causes the command to ask for approval before transferring a file that would overwrite an existing file; you must hit y to approve moving; any other key leaves the file unchanged. If the file doesn't exist, this option will simply rename it or transfer it to a new place. The syntax is:

    $ mv -i demo1.txt demo2.txt

    2. -f (Force)

    If a file is write-protected, mv will ask for confirmation before overwriting it. The - f option overrides this minor safeguard and deletes the source file while overwriting the destination file. The syntax is:

    $ mv -f demo1.txt demo2.txt

    3. -n (no-clobber)

    The - n option prevents mv from overwriting an existing file.

    The consequence in the following example is that nothing happens since a file is rewritten. The syntax is:

    $ mv -n demo1.txt demo2.txt

    4. -b(backup)

    This option makes taking a backup of an existing file that will be replaced by the mv command more easier. This will produce a backup file that includes the tilde character(). The syntax is:

    $ mv -b demo1.txt demo2.txt

    5. –version

    This option displays the version of mv that is presently installed on your system. The syntax is:

    $ mv --version

    6. -u

    When we use the mv command with the - u option to make the file at the destination get updated since the source file is newer.

    $ mv -u demo.text <directory>


    In this article, we went through various available options with the mv command of Linux. We saw how we could do tasks like: get a version of the command, overwrite the destination file, prompting before transferring, etc.

    People are also reading:

    Leave a Comment on this Post