How to Move Files and Directories in Linux

One of the most basic tasks you’ll perform as a Linux user or administrator is moving files and directories. This article covers how to transfer files and directories in both the Linux GUI and the terminal.

For this guide, we’re using Ubuntu LTS 22.04, codenamed Jammy Jellyfish. The Linux commands featured in this article are distro-independent, meaning they will work on any Linux distro.

Note: you can only move files or directories you have appropriate permissions for and only move them to directories to which you have the appropriate permissions.

Moving Files in the GUI

There are several different ways to move files and directories in the Linux GUI. You can select multiple files and directories to move by using the <Ctrl> key when choosing them.

Move Files via Drag and Drop

In this example, we will move a file, yellow.txt, via drag and drop from the source directory, /techobservatory/orange, to the target directory, /techobservatory.

  1. Launch the file manager.
  2. Open both the target directory, /techobservatory, and source directory, /techobservatory.com, containing the specified file, yellow.txt.
  3. Select yellow.txt and while holding down the left mouse button, drag it to the target directory/techobservatory.
  4. Release, or drop the specified file.

    From the file manager, Nautilus, open both the target directory, /techobservatory, and source directory, /techobservatory.com, that contains the specified file, yellow.txt. Select the specified file, yellow.txt, from the source directory, /techobservatory/orange. Drag the specified file, yellow.txt, holding down the left mouse button while dragging, to the target folder, /techobservatory. Release, or drop the specified file, yellow.txt, by releasing the left mouse button.
    Drag and drop the specified file from the source directory to the target directory.
  5. yellow.txt was successfully moved from /techobservatory/orange to /techobservatory.

    You can now see that the specified file, yellow.txt, was successfully moved from the target directory, /techobservatory/orange, to the source directory, /techobservatory.
    The file is transferred to the target directory.

Move via Cut and Paste

In this example, we will move both a specified file, blue.txt, and a specified directory, /techobservatory/pink, from the source directory, /techobservatory, to the target directory, /techobservatory/green.

    1. Launch your distro’s file manager.
    2. Navigate to the source directory, /techobservatory, containing blue.txt, and the specified folder, pink, you want to move. Select both while holding down the <Ctrl> key, then right-click them.

      Navigate to the source directory, /techobservatory, containing the specified file, blue.txt, and the specified directory, pink, you want to copy. Select the specified file, blue.txt, and the specified directory, pink, while holding down the key.
      Select both the file and directory.
    3. Select Cut from the drop-down menu.

      Select Cut from the drop-down menu.
      Select Cut from the drop-down menu.
    4. Navigate to the target directory, right-click your mouse button and select Paste from the drop-down menu

Note: you use the <Ctrl>C and <Ctrl>V shortcuts to copy-paste them.

Move Files via Move To…

Linux distros using GNOME as their desktop environment usually use Nautilus as their default file manager. Nautilus has an option that allows users to right-click and select a Move To… option to move their files and directories.

In this example, we will move the file yellow.txt to the directory /techobservatory/orange.

    1. Launch Nautilus.
    2. Navigate to the source directory, select the file you want to move, and right-click your mouse button. Choose the Move To… option from the drop-down menu.

      Select the specified file you want to copy. Right-click the mouse button. Select Move T...
      Select the specified file you want to move. Right-click the mouse button. Select Move To…
    3. Now, left-click the target directory, /techobservatory/orange.

      At the next window, select the target directory.
      At the next window, select the target directory.
    4. The file will automatically be moved to the target directory.

      The specified file was successfully moved to the target directory.
      The specified file was successfully moved to the target directory.

Moving Files via the Command Line

Linux’s only built-in command to move files is the mv command.

mv Command Purpose, Syntax, and Options

The mv command is used to move or rename files or directories. The syntax of the mv command is:

# mv [options] <source> <destination>

We will only be using the -v option in our examples in this section. The -v option, or verbose, explains what is being done with the moved files or directories.

Real-Life Scenario – Moving Files

In this scenario, we will move the specified file, purple.txt, to the source directory, /techobservatory/green.

  1. Open the terminal.
  2. Change directory to the target directory/techobservatory.
    # cd /techobservatory
  3. Move the specified file, purple.txt, to the specified directory, /techobservatory/green.
    # mv purple.txt /techobservatory/green
  4. Verify that the specified file, purple.txt, was moved to the target directory, /techobservatory/green.
    # ls -Al /techobservatory/green
  5. The specified file, purple.txt, was successfully moved to the target directory, /techobservatory/green.

    The specified directory was succesfully copied to the target directory
    The specified file was successfully moved to the target directory.

Real-Life Scenario – Moving Directories

  1. In this example, we will move the directory /techobservatory/green to the directory /techobservatory/pink.
  2. Open the terminal.
  3. Change to the source directory/techobservatory.
    # cd /techobservatory
  4. Move the specified directory, /techobservatory/green, to the target directory, /techobservatory/pink.
    # mv -v /techobservatory/green /techobservatory/pink
  5. Verify that the specified directory, /techobservatory/green, was moved to the target directory, /techobservatory/pink.
    # ls -AL /techobsevatory/pink
  6. The specified directory, /techobservatory/green, was successfully moved to the target directory, /techobservatory/pink.

    The specified directory was successfully copied to the target directory.
    The specified directory was successfully moved to the target directory.

Real-Life Scenarios – Moving Multiple Files

Move Two or More Files

In this example, we will move the specified files to /techobservatory/auburn.

  1. Open the terminal.
  2. Change to the source directory/techobservatory.
    # cd /techobservatory
  3. Move the specified files, red.txt, blue.txt, and brown.txt,  to the target directory, /techobservatory/auburn.
  4. # mv -v red.txt blue.txt brown.txt /techobservatory/auburn
  5. List the directory contents of the target directory, /techobservatory/auburn.
    # ls -Al /techobservatory/auburn

    The specified files,successfully moved to the target directory.
    The specified files were successfully moved to the target directory.
  6. The specified files, red.txt, blue.txt, and brown.txt, were successfully moved to the target directory, /techobservatory/auburn.

Move Multiple Files Using the Wildcard (*)

In this example, we will move all files beginning with the letter b to the /techobservatory/pink directory using the wildcard (*) option.

  1. Open the terminal.
  2. Change to the source directory/techobservatory directory.
    # cd /techobservatory
  3. Move the target files (all files beginning with the letter b to the target directory, /techobservatory/pink.
    # mv -v b*.* /techobservatory/pink
  4. Verify that the specified files (all files beginning with the letter b) were moved to the target directory, /techobservatory/pink.
    # ls -Al /techobservatory/pink
  5. All of the specified files (all files beginning with the letter b) were successfully moved to the target directory, /techobservatory/pink.

    The target files were successfully moved to the target directory using the wildcard (*) character.
    The target files were successfully moved to the wildcard (*) character using the target directory.

Commands Used In This Article

  • mv – move or rename files.
  • ls – list directory contents.
  • cd – change directory.

Was this article helpful?

Leave a Comment