Move files in the Linux terminal

Use the mv command to move a file from one location to another.
38 readers like this.
Moving files

CC BY-SA Seth Kenlon

To move a file on a computer with a graphical interface, you open the folder where the file is currently located, and then open another window to the folder you want to move the file into. Finally, you drag and drop the file from one to the other.

To move a file in a terminal, you use the mv command to move a file from one location to another.

$ mv example.txt ~/Documents

$ ls ~/Documents
example.txt

In this example, you've moved example.txt from its current folder into the Documents folder.

As long as you know where you want to take a file from and where you want to move it to, you can send files from any location to any location, no matter where you are. This can be a serious time saver compared to navigating through all the folders on your computer in a series of windows just to locate a file, and then opening a new window to where you want that file to go, and then dragging that file.

The mv command by default does exactly as it's told: it moves a file from one location to another. Should a file with the same name already exist in the destination location, it gets overwritten. To prevent a file from being overwritten without warning, use the --interactive (or -i for short) option:

$ mv -i example.txt ~/Documents
mv: overwrite '/home/tux/Documents/example.txt'? 

 

What to read next
Seth Kenlon
Seth Kenlon is a UNIX geek, free culture advocate, independent multimedia artist, and D&D nerd. He has worked in the film and computing industry, often at the same time.

2 Comments

I don't know how mv works internally, but I think of it as carrying out 2 operations: first, copying the file to the new location, then deleting the original.
Another way to think of the mv command is that it renames a file. So, for example, you can leave a file in the same directory or move it to another, changing its name:
mv file.txt file_old.txt
mv file.txt Documents/file_old.txt

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.