- How to Move Files Using Linux Commands or File Managers
- Command line moving
- All the Ways to Move Files in Linux for Beginners
- When to Move:
- Advantages of Moving Data:
- How to Move Files in the Linux System:
- How to Move Files Using the Command-line Tool (Terminal):
- Example 1: Moving a File
- Additional Note:
- Example 2: Moving a Folder Into the Directory
- Example 3: Moving Multiple Files at Once
- How to Move Files Using GUI:
- Conclusion:
- About the author
- Wardah Batool
How to Move Files Using Linux Commands or File Managers
Learn how to move files with Linux commands in this tutorial from our archives.
There are certain tasks that are done so often, users take for granted just how simple they are. But then, you migrate to a new platform and those same simple tasks begin to require a small portion of your brain’s power to complete. One such task is moving files from one location to another. Sure, it’s most often considered one of the more rudimentary actions to be done on a computer. When you move to the Linux platform, however, you may find yourself asking “Now, how do I move files?”
If you’re familiar with Linux, you know there are always many routes to the same success. Moving files is no exception. You can opt for the power of the command line or the simplicity of the GUI – either way, you will get those files moved.
Let’s examine just how you can move those files about. First we’ll examine the command line.
Command line moving
One of the issues so many users, new to Linux, face is the idea of having to use the command line. It can be somewhat daunting at first. Although modern Linux interfaces can help to ensure you rarely have to use this “old school” tool, there is a great deal of power you would be missing if you ignored it all together. The command for moving files is a perfect illustration of this.
The command to move files is mv . It’s very simple and one of the first commands you will learn on the platform. Instead of just listing out the syntax and the usual switches for the command – and then allowing you to do the rest – let’s walk through how you can make use of this tool.
The mv command does one thing – it moves a file from one location to another. This can be somewhat misleading, because mv is also used to rename files. How? Simple. Here’s an example. Say you have the file testfile in /home/jack/ and you want to rename it to testfile2 (while keeping it in the same location). To do this, you would use the mv command like so:
mv /home/jack/testfile /home/jack/testfile2
or, if you’re already within /home/jack:
mv testfile testfile2
The above commands would move /home/jack/testfile to /home/jack/testfile2 – effectively renaming the file. But what if you simply wanted to move the file? Say you want to keep your home directory (in this case /home/jack) free from stray files. You could move that testfile into /home/jack/Documents with the command:
mv /home/jack/testfile /home/jack/Documents/
With the above command, you have relocated the file into a new location, while retaining the original file name.
What if you have a number of files you want to move? Luckily, you don’t have to issue the mv command for every file. You can use wildcards to help you out. Here’s an example:
You have a number of .mp3 files in your
/ – is an easy way to represent your home directory – in our earlier example, that would be /home/jack/) and you want them in
/Music. You could quickly move them with a single command, like so:
That command would move every file that ended in .mp3 from the Downloads directory, and move them into the Music directory.
Should you want to move a file into the parent directory of the current working directory, there’s an easy way to do that. Say you have the file testfile located in
/Downloads and you want it in your home directory. If you are currently in the
/Downloads directory, you can move it up one folder (to
The “../” means to move the folder up one level. If you’re buried deeper, say
/Downloads/today/, you can still easily move that file with:
Just remember, each “../” represents one level up.
As you can see, moving files from the command line, isn’t difficult at all.
There are a lot of GUIs available for the Linux platform. On top of that, there are a lot of file managers you can use. The most popular file managers are Nautilus (GNOME) and Dolphin (KDE). Both are very powerful and flexible. I want to illustrate how files are moved using the Nautilus file manager (on the Ubuntu 13.10 distribution, with Unity as the interface).
Nautilus has probably the most efficient means of moving files about. Here’s how it’s done:
Open up the Nautilus file manager.
Locate the file you want to move and right-click said file.
From the pop-up menu (Figure 1) select the “Move To” option.
When the Select Destination window opens, navigate to the new location for the file.
Once you’ve located the destination folder, click Select.
This context menu also allows you to copy the file to a new location, move the file to the Trash, and more.
If you’re more of a drag and drop kind of person, fear not – Nautilus is ready to serve. Let’s say you have a file in your home directory and you want to drag it to Documents. By default, Nautilus will have a few bookmarks in the left pane of the window. You can drag the file into the Document bookmark without having to open a second Nautilus window. Simply click, hold, and drag the file from the main viewing pane to the Documents bookmark.
If, however, the destination for that file is not listed in your bookmarks (or doesn’t appear in the current main viewing pane), you’ll need to open up a second Nautilus window. Side by side, you can then drag the file from the source folder in the original window to the the destination folder in the second window.
If you need to move multiple files, you’re still in luck. Similar to nearly every modern user interface, you can do multi-select of files by holding down the Ctrl button as you click each file. After you have selected each file (Figure 2), you can either right-click one of the selected files and the choose the Move To option, or just drag and drop them into a new location.
The selected files (in this case, folders) will each be highlighted.
Moving files on the Linux desktop is incredibly easy. Either with the command line or your desktop of choice, you have numerous routes to success – all of which are user-friendly and quick to master.
Источник
All the Ways to Move Files in Linux for Beginners
When you switch from Windows to Linux system, the question may arise in the beginners’ mind on “How can we move files?” In Linux, there are several routes to reach the same destination, and Linux distributions are designed to make the system easy to use for all types of users.
Before getting started with moving files, let’s discuss what moving the files means? This might be helpful for the beginners confused with the move(mv) and copy(cp) command.
Moving a file or folder means to cut the file from the previous location and paste it to the new location. To put it in another way, moving is transferring the original content to a new location and removing it from the old location. When we move the file, the file gets deleted from the previous directory and added to a new destination, whereas in copying, the files stay in the source directory.
Now, I think that’s enough to understand the term “moving files.”
The difference between Copy and Move is that the “Move” relocate the file to a new destination while “Copy” means to create a duplicate of the content and paste it into the new destination.
Copying a file uses copy (Ctrl+C) and paste (Ctrl+V) keys; whereas, moving means “Cut (Ctrl+X) and Paste (Ctrl+V).”
When to Move:
Moving data files is useful when users want to keep one version and don’t want to duplicate the content. It would be good if you are careful while doing this because you could lose the original file in case of any mistake during the process, which may be a great loss.
Advantages of Moving Data:
There are several possibilities that explain to you why moving data is necessary.
Let’s demonstrate them:
It is good to move the file instead of copying them when you are working on different systems. If you are not supposed to work only on one workstation; you can transfer the document you’re working on to another system and continue. Moving data also helps when you migrate to a new system. Moreover, it can also be handy for backup purposes. If your hard drive is short on storage and you want to archive data into another storage device, it is good to move them instead of deleting them.
Or, if the system isn’t connected to external devices like the printer and scanner, you can transfer the files you want to print to the system connected with the printer.
We have discussed briefly moving the files and why anyone needs to move data. Also, we have discussed its advantages and saw how moving is different from copying data.
Now, it is easy to move forward to find how we can move files in the Linux Operating System:
How to Move Files in the Linux System:
There is no traditional way to perform move operation; in Linux distributions,
a couple of methods are used to move files:
- Through the command-line tool (Terminal)
- Through Graphical User Interface (GUI)
How to Move Files Using the Command-line Tool (Terminal):
The command used for moving files from the source location to a particular destination is the “mv” command:
The “mv” command-line tool is considered as a multi-purpose command. It is not only used to transfer files from source to destination but also used to rename a file or folder:
Syntax:
The syntax of the “mv” command is:
Before starting the examples to move files using the “mv” command, there’s another point we need to understand.
When a file or folder is created, an “inode” is assigned to the file/directory, which contains the metadata of the file. The full form of “inode” is “index node” that explains the file-system object like whether it is a file or directory and stores the information about the representative file like permission access, type of file, group, size, etc. The index node is a string of integers, and each inode is unique.
To check the inode of a specific file, the syntax is mentioned:
If I want to check the inode value of text file “sample.txt”, the command would be:
Whenever you move a file, it’s not about moving the data from one inode to another; you only change the path. Its permission access setting would remain the same as before. It is because you’re not changing the file or re-creating it, and only its path in the memory has changed.
Now, let’s check how the “mv” command is helpful to move files through different examples.
Example 1: Moving a File
Create a sample file “sample_file.txt” using the “touch” command in the “Home” directory:
Use the “mv” command to move the file into the “Documents” directory; the following command detects “Documents” as a directory/folder and transfers the “sample_file.txt” into it:
To confirm the existence of “sample_file.txt” in the Documents directory, run the “ls” command in the terminal:
Note: You must write permission to access the Source and Destination to move a file. Otherwise, it will show the permission denied error message.
Additional Note:
Some folks get confused while giving the source and destination path, so they get the wrong results. However, there’s an easy way to find the path of any directory or file, which is mentioned below:
Select the folder/directory you want to get the path of and right-click on it. In the Popup menu, navigate towards “Properties” and click on it,
For example, I want to find the path of “text.txt” folder in the home directory:
When you hit the “Properties”, it will show you all the necessary details of the “text.txt” with the path:
From there, you can copy the path and paste it in terminal.
Once you moved the file, you can rename it using the “mv” command again:
Let’s check through the “ls” command if the file’s name has changed or not:
Example 2: Moving a Folder Into the Directory
Just like in the example above, we moved a file from one location to another. Similarly, there’s no separate way to move the directory as in the “cp” command.
The approach is the same as we did above using the “mv” command:
Create a testing folder and set the name as “testing” using the “mkdir” command. Add the random file in it, like create a “testing.txt” file in it through the “touch” command:
Move the “Testing.txt” file in the “Testing” folder using the “mv” command:
Now, move the “Testing” folder into the “Downloads” directory:
To confirm, type:
Example 3: Moving Multiple Files at Once
When we move multiple files at the same time, the “mv” command considers the last directory name as the destination directory:
Let’s move files “sample.txt”, “testing.txt”, and “test.txt” in the “Downloads” directory. For this, open the terminal in the “Documents” directory as all of these files are placed there:
Execute the “ls” command to confirm it:
As you can see, all files are successfully transferred from the “Documents” directory to the “Downloads” directory.
How to Move Files Using GUI:
There are multiple GUI tools and file management systems available for Linux operating system. The widely used ones are Nautilus, a GNOME file manager, and Dolphin, which is a file manager for KDE. These two file managers are preferred because of their flexibility.
I am currently working on Ubuntu 20.04 that uses a Gnome desktop environment. Therefore, we will see how we can move files from one directory to another through the Nautilus file manager.
GUI makes file transfer relatively easy. We just have to follow a few simple sentences that are listed below:
- Open the Nautilus file manager in the system you’re working on.
- Choose the file you want to relocate and right-click on it.
- A Context menu will appear on the screen and navigate towards “Move to” options.
- Once you clicked on the “Move to” option, a window with the list of possible destination directories will appear in front of you.
- Select the new location you want to transfer the file into and press “Select”.
Let’s understand it through an example:
Open the Nautilus file manager in the Ubuntu 20.04:
For the folks confused with the term “Nautilus”, it is just the name of the File manager. And if you are wondering on how to get it, let me display it more explicitly.
Open the applications menu, search for the file manager, and type “nautilus” or “Files”:
You can see, after typing the nautilus, it reveals the “Files” option. Click on it to get the file manager window:
As dsiplayed, there are multiple folders and some text files in it. Suppose I want to move the “sample.txt” text file into another location. Select the “sample.txt” file and right-click on it:
Click on “Move to…”, a list of all possible destinations will appear on the screen:
Let’s move the “sample.txt” file to the “Documents” directory. Then, choose it from the window and hit the “Select” button:
The files have been successfully moved from the “Home” directory to the “Documents” directory.
As you can see, “sample.txt” is no longer present in the “Home” directory:
To verify if it is successfully moved to the destination, open the “Documents” directory and check if the “sample.txt” file exists:
Similarly, if you want to move a directory to another location, you can also do it by repeating the same steps we discussed above. Let’s review it through an example,
create a new folder in the “Home” directory and name it. I am creating a folder by the name of “Testing”, as shown in the following image:
Imagine that we want to move the “Testing” directory/folder to the Downloads directory. So, select the “Testing” folder, right-click on it, and in the sub-menu, navigate towards the “Move to…” option:
A window will open, select the “Downloads” directory to transfer the “Testing” folder to it by clicking the “Select” button:
Confirm the moved folder existence in the “Downloads” directory by opening it in the file manager:
As you can see, it is simple to move a file or directory through the “Nautilus” file manager:
Conclusion:
In this guide, we have an in-depth explanation for beginners on how to move files in Linux. Moving a file is not a difficult task if you know exactly how to do it. In a Linux system, we have several ways to perform a single operation as they are designed to make the system comfortable for all types of users.
We have briefly discussed a couple of ways of transferring files to another location in your system. Approaches to move files or folders, such as through GUI and Terminal, are pretty simple and relatively straightforward as it does not require you to be an expert to utilize these approaches. This guide is beneficial as you get a step-by-step discussion of the two different procedures.
For me, both methods are quick and less complex. If you move a file through GUI, simply right-click on the target file and click on the “Move to…” option in the context menu. A window will appear for you to select the destination directory to transfer the file. The file will be removed from the previous location.
If you prefer to use a terminal, then the “mv”, a multi-purpose command, is used. It is not only used to move files/folders but also to rename them. We have performed multiple examples of the “mv” command for better understanding. The procedure is similar in each example; if you follow one example carefully, then you can use the “mv” command anywhere.
About the author
Wardah Batool
I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.
Источник