Moving or copying files or folders in Linux: the best solution

LINUX files

In principle, the task of copy move file linux. And it really isn't, as long as you have one Graphic interface, that is, a desktop environment. And this is so in most cases. A couple of clicks is enough.

However, we may encounter the unpleasant situation. Not that it is normal, but with Linux sometimes happens: the graphical environment that makes life so easy is not available. We are lost, like groping in a darkened room. When this happens, it is necessary to have resources and solutions to carry out the most common operations. That's what today's post is about, focusing on the tasks related to copying and moving Linux files.

Praise towards Linux for the quality of its code and the great acceptance of the free system in so many technological sectors they are well deserved. But that is precisely why it draws so much attention that so many problems related to the operation of your desktop. That also has a very negative impact that is reflected in its market share. Linux represents only 2% of the world market share of computer desks, a market dominated by Windows with more than 90%.

But let's go back to the central theme of the post: to Linux and the question of "how do I move files?". Those who know this platform know well that there are many ways and methods to achieve the same goal. It is that so old and so reassuring of "all roads lead to Rome." This also applies to the tasks of copy move file linux

Commands to copy move Linux file

Copy move Linux file

Let's examine how these files can be moved. The first that we have to do open a terminal, which will be our tool with which to execute all the actions. It is also convenient to create some folders with text documents inside. It is simply a caution so we don't have to regret it after we have damaged or lost important information.

It is very common for novice Linux users to feel terrified (or sometimes lazy) when it comes to use a command line. However, once they break that invisible barrier and get used to using this system, they realize all the possibilities that open before them and want to learn more. What we are going to explain below can be a good first step to get started:

The command used to move some file from one to another folder is the command etc. This is one of the first commands that you usually learn when you start using this platform. Let's see how you can make use of this tool. Here is an example:

mv file.txt / home / user / Documents / myfiles

With this command we are moving the file.txt to the folder that we have named "My files" (it is just an example) that is located in our documents folder. In order for it to work, at the time of entering the command, it must be located in the directory where file.txt is located.

What we want may be move not one, but multiple files at once. No, it is not necessary to issue the command mv for each file. Help wildcards can be used. We explain it with an example: suppose we have multiple .mp3 files in our directory ~ / Downloads (~ / - is an easy way to represent the home directory; in the example above it would be / home / user /) and we want to move them to ~ / Music. Well, to execute this action what we must write is the following:

mv ~ / Downloads / *. mp3 ~ / Music /

And so, thanks to that command, all the files ending in .mp3 would be moved from the Downloads directory to the Music directory.

Move files and rename them

vv linux

How to use the mv command in Linux

With the command mv you have to be very cautious. It is true that it will help us to move a file from one location to another. But nevertheless, can also be used to rename files. We explain it to you with an example:

Suppose we have the file named "test" in the / home / myfiles / folder and we want to rename it "new" without changing its location. In this case, you should use the command mv in this way:

mv / home / myfiles / test / home / myfiles / new

Although if we are already inside the / home / myfiles folder, it would be enough to write the following:

mv test new

Let's analyze another assumption. Now it's about move the file, but keeping the home directory  / home / myfiles free from lost files. To do this you can move that test file to / home / myfiles / Documents with the following command:

mv / home / myfiles / test / home / myfiles / Documents /

By doing this, the file will have been moved to a new location, but retaining the original file name.

Copy files in Linux

How to use the cp command in Linux

Copy move file Linux are very similar operations in their execution mode. The big difference is that, instead of moving the files from one folder or directory to another, they will stay in their initial location at the time they are created. a copy in the new chosen directory.

The command used in Linux to copy is the command cp. Following the previous example, it would be expressed like this:

cp test / path / to / destination

With this, a copy of the "test" file would appear in its new location without the file disappearing from its original folder. Now, if what we want is copy multiple files from the same folder (for example the files "test" and "test2"), the command would be this:

cp test / test2 / path / to / destination

Move a file to a higher folder

If what we want is to move a file to the main directory (or just a higher one) from the current working directory, there is an easy way to do it.

Let's imagine that the file in question is the same as before, called "test", which we have located in ~ / Downloads. And what do we want move it to the top folder which in turn contains the one for ~ / Downloads and is called / Myfiles. That, said in a visual way, would be something like "uploading" the file to the folder of another level. And it's as simple as this:

mv test ../

The symbol set ../ means to move the folder up one level. If the file to be moved were stored in a folder within another folder, that is, still another level below, the command would have to be expressed as follows:

mv test ../../

The only thing to remember is that each ../ represents one more level.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Actualidad Blog
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.