How To Move Files Using Linux Graphical And Command Line Tools

Move and rename your files In Linux

The easiest way to move files around is using the file manager that comes with your particular Linux distribution. A file manager provides a graphical view of the folders and files that are stored on your computer. Windows users will be familiar with Windows Explorer which is a type of file manager.

The most commonly used file managers in Linux are as follows:

  • Nautilus
  • Dolphin
  • Thunar
  • PCManFM
  • Caja

Nautilus is part of the GNOME desktop environment and is the default file manager for Ubuntu, Fedora, openSUSE and Linux Mint.

Dolphin the part of the KDE desktop environment and is the default file manager for Kubuntu and KaOS.

Thunar comes with the XFCE desktop environment, PCManFM is installed with the LXDE desktop environment and Caja is part of the MATE desktop environment.

A desktop environment is a collection of graphical tools which allow you to administer your system.

How to Use Nautilus to Move Files

  1. If you are using Ubuntu you can open the Nautilus file manager by selecting the filing cabinet icon at the top of the launcher.

    For others of you using the GNOME desktop environment press the super key on the keyboard (usually has the Windows logo and is next to the left alt key) and search for Nautilus in the box provided.

  2. When you have opened Nautilus you will see the following options in the left panel:

    • Recent places
    • Home
    • Desktop
    • Downloads
    • Music
    • Pictures
    • Videos
    • Rubbish Bin
    • Other Locations
    Left pane in Nautilus
  3. Most of your files will be below the Home folder. Opening a folder shows a list of subfolders and files within that folder.

  4. To move a file, right-click it and choose Move To.

    Move to command in the option menu of Nautilus
  5. A new window will open. Navigate through the folder structure until you find the directory where you want to place the file.

  6. Press Select to finalize the move.

    Select button in Move Destination window in Nautilus

How to Move Files Using Dolphin

Dolphin is available by default with the KDE desktop environment. If you aren't using KDE then you should stick with the file manager that came with your distribution.

File managers are very much alike and there is no good reason to install a different one to the default for your system.

Dolphin doesn't have a context menu for moving files. Instead, all you have to do to move files is drag them to the desired location.

The steps for moving files are as follows:

  1. Navigate to the folder where the file is located.

    Linux Dolphin file in folder
  2. Press Split in the upper right of the window.

    Split button in Dolphin
  3. In the new tab, select the arrow next to the folder name. Use the menu that appears to navigate to the folder you wish to move the file to.

    Folder arrow in Dolphin
  4. Go back to the original tab and drag the file you wish to move to the new tab.

    Dragging a file to a new folder in Dolphin
  5. A menu will appear with the option to Move Here.

    Move Here command in option menu in Dolphin
  6. Press Close, which as replaced Split to close the tab.

    You can also feel free to right click the file, and select Copy. Then, navigate to the folder where you want the file, and right click again, this time selecting Paste.

    Close button in Dolphin

How to Move Files Using Thunar

Thunar has a similar interface to Nautilus. The left panel, however, is separated into three sections:

  • Devices
  • Places
  • Network

The devices section lists the partitions available to you. The places section shows items such as Home, Desktop, Rubbish bin, Documents, Music, Pictures, Videos, and Downloads. Finally, the network section lets you browse network drives.

Most of your files will be under the home folder but you can also open the file system option to get to the root of your system.

  1. Thunar uses the concept of cut and paste to move items around. Right-click on the file you wish to move and choose Cut from the context menu.

    Cut option in Thunar
  2. Navigate to the folder where you wish to place the file.

  3. Right-click in the empty space, and choose Paste.

    Paste command in Thunar

How to Move Files Using PCManFM

PCManFM is also similar to Nautilus. 

The left panel has a list of places as follows:

  • Home
  • Desktop
  • Rubbish bin
  • Applications
  • Documents
  • Music
  • Pictures
  • Videos
  • Downloads

You can navigate through the folders by clicking on them until you find the file you wish to move.

  1. The process of moving files is the same for PCManFM as it is for Thunar. Right-click on the file, and choose Cut from the context menu.

    Cut command in PCManFM
  2. Navigate to the folder where you wish to place the file.

  3. Right click again, and choose Paste.

    Past command in PCManFM

How to Move Files Using Caja

The Caja file manager is the default option for Linux Mint MATE and it is virtually the same as Thunar.

  1. To move a file navigate through the folders by clicking with the left mouse button.

  2. When you find the file you wish to move, right-click and choose Cut.

    You will notice on the right click menu that there is a Move To option but the places where you can move files to using this option are very limited. 

    Cut command in Caja
  3. Navigate to the folder where you wish to put the file, right-click and choose Paste.

    Paste command in Caja

How To Move Files Using The MV Command

On Linux, the mv command can move files and folders around your computer. You only need to tell mv which file or folder you want to move and give it a destination to place it in. Try it with something simple first.

  1. Open a terminal window, either by through your applications menu or with the Ctrl+Alt+T hotkey.

  2. Look for a file that you want to move. You can do this with the ls command.

    ls ~/Downloads
  3. Say you found a document that you just downloaded for work, and you need to move it to your Documents directory. Give mv the full path to where the file is, and tell it which folder to move it to.

    mv ~/Downloads/work-doc.odt ~/Documents/
  4. Now, check your Documents directory to see it there.

    ls ~/Documents | grep -i work-doc

Move And Sort Multiple Files At Once

Moving one file at a time can be tedious, and it provides no advantage over the graphical way. However, the command line is built for flexibility, and it allows you to easily move and organize multiple files at once.

Imagine that you have copied a large number of photos from your digital camera to the Pictures folder under your home folder. (~/Pictures). 

Having lots of pictures under a single folder makes them difficult to sort through. It would be better to categorize the images in some way. 

You could, of course, categorize the images by year and month or you could categorize them by a particular event.

For this example lets assume that under the pictures folder you have the following files:

  • img0001_01012015.png
  • img0002_02012015.png
  • img0003_05022015.png
  • img0004_13022015.png
  • img0005_14042015.png
  • img0006_17072015.png
  • img0007_19092015.png
  • img0008_01012016.png
  • img0009_02012016.png
  • img0010_03012016.png

It is hard to tell by the photos what they actually represent. Each file name has a date associated with it so you can at least place them in folders based on their date.

  1. When moving files around the destination folder must already exist otherwise you will get an error.

    To create a folder, use the mkdir command as follows:

    mkdir -p {2015,2016}/{January,February,March,April,May,June,July,August,September,October,December}

    That might seem like a lot, but it's actually a lot simpler than doing it all manually. The '-p' switch lets the mkdir command create an entire folder path at once.

    Then, the brackets let you list multiple things to apply the same action to. So, this command creates two parent folders for 2015 and 2016, each with a folder for every month.

  2. With the folders created you can now begin to move the image files into the correct folders as follows:

    mv img*012015.png 2015/January/.

    There are a couple of things to break down here. First, the asterisk(*) character is a wildcard that tells mv to move any file that begins with "img" and ends with "012015.png" Essentially, it cuts out the pieces that change in the middle between files and uses only the information that counts, the month and year. This way, you can conveniently move multiple files that meet the same criteria at once.

    The period (.) at the end of the line is what is known as a metacharacter. It basically makes sure the file keeps the same name. It's not strictly necessary, though. You can leave it off and achieve the same result.

  3. Try again with the other files. The pattern remains the same, using the month and year to sort your files.

    mv img*022015.png 2015/February/.
    mv img*042015.png 2015/April/.
    mv img*072015.png 2015/July/.
    mv img*092015.png 2015/September/.
    mv img*012016.png 2016/January/.
  4. That's all you'd need to move and sort all of the files from that list. Clearly, if you had more files, this method could save serious time over moving them with a graphical file manager.

How to Rename a File Using the Linux mv Command

Whilst the files are now nicely sorted by date it would be nice to know what each image contains. Really the only way of doing this is to open the file in an image viewer. Once you know what the image is about you can rename the file using the mv command as follows:

mv img0008_01012016.png newyearfireworks.png

That's really all there is to renaming with mv. It actually doesn't require any special syntax to rename files. Just supply a destination file name.

What Happens If the File Already Exists

The bad news is that if you move a file to a folder where there is already a file of the same name then the destination file is overwritten.

There are ways to safeguard yourself. You can make a backup of the destination file by using the following syntax.

mv -b test1.txt test2.txt

This renames test1.txt to become test2.txt. If there is already a test2.txt then it will become test2.txt~.

Another way to safeguard yourself is to get the mv command to tell you if the file already exists and then you can choose whether to move the file or not.

mv -i test1.txt test2.txt

If you are moving hundreds of files then you will probably write a script to perform the move. In this instance, you won't want a message to appear asking whether you want to move the file or not.

You can use the following syntax to move files without overwriting the existing files.

mv -n test1.txt test2.txt

Finally, there is one more switch which lets you update the destination file if the source file is more recent.

mv -u test1.txt test2.txt
Was this page helpful?