Complete Guide to Moving Files in Ubuntu | How to Use GUI and CLI Effectively

1. Introduction

Ubuntu is a popular Linux distribution known for its ease of use and flexibility. File management is one of the essential tasks for developers and system administrators.

In this article, we will explain how to move files in Ubuntu, covering both GUI (Graphical User Interface) and CLI (Command Line Interface) methods. By providing multiple approaches, users can choose the method that best suits their skill level and preferences.

By reading this article, you will learn:

  • Simple file-moving techniques using the GUI
  • Flexible operations using the mv command
  • Important considerations for permissions and errors

Let’s dive into the details of file moving in Ubuntu.

2. Moving Files Using the GUI

Ubuntu provides an intuitive GUI tool for file operations. In this section, we will introduce how to move files using the default file manager, “Files.”

2.1 Opening the File Manager

Ubuntu’s default file manager is called “Files.” You can open it using the following methods:

  1. Click the “Files” icon in the left-side activity bar.
  2. Alternatively, press the “Super Key” (equivalent to the Windows key) to open the search bar, type “Files,” and press Enter.

Now, the file manager will open, allowing you to visually navigate through directories.

2.2 Moving Files via Drag & Drop

The simplest way to move files and folders is by using drag and drop. Follow these steps:

  1. Select the file or folder you want to move in the file manager.
  2. Open the destination folder in a separate window or within the same window.
  3. Drag the selected file and drop it into the destination folder.

The file will be successfully moved.

2.3 Moving Files via Copy & Paste

Another convenient method is to use the copy-and-paste functionality. Follow these steps:

  1. Right-click the file you want to move and select “Cut.”
  2. Open the destination folder, right-click inside it, and select “Paste.”

You can also use keyboard shortcuts:

  • Cut: Ctrl + X
  • Copy: Ctrl + C
  • Paste: Ctrl + V

These shortcuts allow for more efficient navigation, especially for users who prefer keyboard-based operations.

侍エンジニア塾

3. Moving Files Using the Terminal

Ubuntu allows you to move files and folders efficiently using the terminal. This section will provide a detailed explanation of the mv command and its useful options.

3.1 Basics of the mv Command

The mv command is used in the terminal to move files. It stands for “move” and can also be used to rename files.

Basic syntax:

mv [options] source destination
  • Source: The path of the file or folder to be moved
  • Destination: The target path where the file will be moved

Example:

mv file1.txt /home/user/Documents/

This command moves file1.txt from the current directory to the Documents folder.

3.2 Moving Files

Moving a file to another folder:

mv example.txt /home/user/Desktop/

This command moves example.txt to the Desktop.

Moving multiple files simultaneously:

mv file1.txt file2.txt /home/user/Documents/

This moves two files at the same time to the Documents folder.

3.3 Moving Directories

Directories (folders) can also be moved using the mv command.

Moving a folder to another location:

mv folder1 /home/user/Documents/

This moves folder1 to the Documents folder.

Moving all contents within a folder:

mv folder1/* /home/user/Documents/

This moves all files and subfolders inside folder1 to Documents.

3.4 Renaming Files and Directories

Renaming a file:

mv oldname.txt newname.txt

This changes the file name from oldname.txt to newname.txt.

Renaming a folder:

mv oldfolder newfolder

Similarly, you can rename a folder using the mv command.

4. Important Considerations & Best Practices

When moving files in Ubuntu, it’s essential to be aware of overwrite risks and permission issues. This section will introduce ways to avoid common problems and work efficiently.

4.1 Preventing Overwrite Risks

Risk of overwriting files:
The mv command automatically overwrites files with the same name in the destination folder, which can lead to data loss.

How to prevent this:

  1. Use the -i option for overwrite confirmation.
mv -i file1.txt /home/user/Documents/

→ You will be asked for confirmation before overwriting.

  1. Use the -n option to prevent overwriting.
mv -n file1.txt /home/user/Documents/

→ The move will be skipped if a file with the same name already exists.

4.2 Handling Permission Issues

Permission denied error:
If you try to move system files or another user’s files, you might see a “Permission denied” error.

Solutions:

  1. Check file permissions.
ls -l file1.txt
  1. Modify permissions.
sudo chmod 755 file1.txt
  1. Use administrative privileges.
sudo mv file1.txt /etc/config/

→ Use sudo with caution, as it grants administrator-level access.

4.3 Improving Efficiency with Wildcards

Using wildcards in the terminal can significantly speed up file operations. Below are some commonly used wildcard patterns.

Moving all .txt files:

mv *.txt /home/user/Documents/

→ Moves all files with the “.txt” extension to the “Documents” folder.

Moving files that start with “log”:

mv log* /home/user/Logs/

→ Moves all files whose names begin with “log” to the “Logs” folder.

Wildcards can greatly enhance efficiency when handling multiple files at once.

5. Summary

In this article, we covered different methods for moving files in Ubuntu, both through the GUI and the terminal.

5.1 Key Takeaways

  • For beginners, the GUI provides an intuitive way to move files using drag-and-drop or copy-and-paste.
  • The terminal mv command offers more flexibility and speed, making it ideal for advanced users.
  • To prevent accidental overwrites, use the -i or -n options.
  • Permission issues can be resolved by checking file ownership and using sudo when necessary.
  • Wildcards allow for efficient batch file operations.

By understanding both GUI and CLI methods, you can choose the best approach based on your workflow and experience level.

5.2 Further Reading

If you want to learn more about Linux file management, check out the following articles:

We hope this guide helps you work efficiently with file operations in Ubuntu. If you have any questions, feel free to leave a comment below!

Example of using the mv command in Ubuntu terminal
侍エンジニア塾