Move Linux files and directories with the mv command

Linux move/rename files FAQ: How do I rename or move Linux files and directories?

You use the Linux mv command to rename or move Linux files and directories. Let's look at some move/rename examples.

Using Linux mv to rename files and directories

At its most basic, here's how you rename a Linux file:

mv Chapter1 Chapter1.old

This mv command renames the file Chapter1 to the new filename Chapter1.old. (Renaming a file is the same as moving it.)

You can use the same technique to rename directories, like this:

mv Directory1 Directory1.old

Using the mv command to move files

As its name implies, you can also use the Linux mv command to move files and directories, moving them from one directory to a different directory. This is how to move a file named file1 to the /tmp directory:

mv file1 /tmp

Similarly, if you wanted to move that file to a subdirectory named Subdir, you'd do it like this:

mv file1 Subdir

Or if you want to move it up one level in the directory hierarchy you'd do it like this:

mv file1 ..

You can also move many files at one time, as shown in this example, where three files are moved to the /tmp directory:

mv file1 file2 file3 /tmp

Using the mv command to move directories

You move directories just like you move files, so if you have a directory named MyStuff, you can move it to the /tmp directory like this:

mv MyStuff /tmp

You can also move it to your home directory, using the ~ character, like this:

mv MyStuff ~

If you're not familiar with using the ~ symbol, it's a shortcut way of referring to your home directory (which in my case is /home/al).

Linux mv summary

I hope this collection of Linux mv commands has been helpful. As you can see, you use the mv command to move or rename Linux files or directories. You can move/rename one file or directory, or many files or directories with one command, as needed.

This website is a little one-man operation. If you found this information helpful, I’d appreciate it if you would share it.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.