MV: Moving Files and Directories in Linux

How to move files or directories using the mv command in Linux.

895 views

Edited: 2019-12-11 12:23

Linux tutorial

The mv command can be used both to rename, and to move files and directories in Linux from a console.

Note. If you struggle to remember how the command is used, then you should check out project humanize to get a dialogue based interface.

Here is an example of how to use the mv command:

mv [file_or_directory] [new_location]

To rename a file or directory, simply write a different destination name:

mv ~/Documents/my-document-txt ~/Documents/new-name.txt

If you do not type a destination file name, the file or directory will just be moved to the new location. I.e.:

mv ~/personal-files/ ~/Documents/

This will move the personal-files directory to the Documents folder.

The mv command works both with absolute and relative paths.

MV and Special Variables

The magic variable $HOME can be used to refer to the current users home directory

The tilde (~) character has special meaning in the shell, and can be used to refer to other users home directories, as well as the current user.

# Current user (self)
~/Documents

# Linking to Other users home
~Other_User/Documents

Tell us what you think:

  1. Understanding file permissions in Unix / Linux based systems, and how to make files immutable.
  2. How to search a directory and subdirectories for a given string of text in Linux with the grep command.
  3. Worth knowing in order to make a bootable USB memory stick with Windows on from Linux.
  4. This is why I decided to encrypt my new Flash Drive, and why I think you should too.
  5. About the problem with using sudo with graphical programs in Linux.

More in: Linux Tutorials