How To Move Files Using Linux Graphical And Command Line Tools

Move Files Using Linux

Lifewire / Juergen Haas

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

If you are using Ubuntu you can open the Nautilus file manager by clicking on 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.

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

Most of your files will be below the "Home" folder. Clicking on a folder shows a list of subfolders and files within that folder.

To move a file right-click on the file and choose Move To. A new window will open. Navigate through the folder structure until you find the directory where you want to place the file.

Click Select to physically move the file.

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.
  2. Right-click on the tab and choose New Tab.
  3. In the new tab navigate to the folder you wish to move the file to.
  4. Go back to the original tab and drag the file you wish to move to the new tab.
  5. A menu will appear with the option to Move Here.

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.

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.

Navigate to the folder where you wish to place the file, right-click and choose Paste.

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.

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.

Navigate to the folder where you wish to place the file, right click again and choose Paste.

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.

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

When you find the file you wish to move, right-click and choose Cut. Navigate to the folder where you wish to put the file, right-click and choose Paste.

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. 

How to Rename a File Using the Linux mv Command

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.

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 <foldername>

In the example given above, it would be a good idea to create a folder for each year and within each year folder there should be folders for each month.

For example:

mkdir 2015

mkdir 2015/01_Januarymkdir 2015/02_Februarymkdir 2015/03_Marchmkdir 2015/04_Aprilmkdir 2015/05_Maymkdir 2015/06_Junemkdir 2015/07_Julymkdir 2015/08_Augustmkdir 2015/09_Septembermkdir 2015/10_Octobermkdir 2015/11_Novembermkdir 2015/12_Decembermkdir 2016mkdir 2016/01_January

Now you may be wondering why we created each month folder with a number and a name (i.e 01_January).

When running a directory listing by using the ls command the folders are returned in alphanumerical order. Without the numbers, April would be first and then August etc. By using a number in the folder name it guarantees the months are returned in the correct order.

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

mv img0001_01012015.png 2015/01_January/.

mv img0002_02012015.png 2015/01_January/.mv img0003_05022015.png 2015/02_February/.mv img0004_13022015.png 2015/02_February/.mv img0005_14042015.png 2015/04_April/.mv img0006_17072015.png 2015/07_July/.mv img0007_19092015.png 2015/09_September/.mv img0008_01012016.png 2016/01_January/.mv img0009_02012016.png 2016/01_January/.mv img0010_03012016.png 2016/01_January/.

In each of the lines of code above the image is copied to the relevant year and month folder based on the date in the file name.

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.

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

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