You are at the beginning of your journey into the world of Linux and are wondering how to effectively manage files and folders? In this guide, you will learn how to copy, move, and rename files and folders. These basic commands will help you master working in the terminal and increase your efficiency. Let's dive straight into the action and get to know the most important commands.

Key Takeaways

  • You will better understand the basic Linux commands CP (Copy) and MV (Move).
  • You will learn how to efficiently copy, move, and rename files and folders.
  • The use of wildcards and options for command customization will be explained.

Creating and Preparing Files and Folders

Before you start copying and moving, you should ensure you have the necessary files and folders available. First, create a folder to organize the files you want to work with. This is done using the mkdir command. You can create a new folder with the following command:

mkdir Papier
Managing files and folders under Linux - Copying and moving made easy

Now you have a new folder named "Papier". You can now add some files that you want to move and copy later.

Moving Files with the MV Command

To move multiple files into the "Papier" folder, you use the MV command. This command allows you to move not only files but also to rename them.

As an example, you want to move all files that start with "Papier" into your newly created folder. The command for this might look like this:

mv Papier* Papier/

By using the * (wildcard) in "Papier*", you can address all files that start with "Papier". The tab key will help you here to ease the input and display the available options.

Once you have executed the command, you can check the status by displaying the contents of the "Papier" folder with ls:

ls Papier
Managing files and folders in Linux – Copying and moving made easy

Copying Files with the CP Command

Now we come to copying files and folders. To copy the "Papier" folder and create a second copy named "Papier 2", you use the CP command:

cp -R Papier/ Papier2/

The -R (recursive) parameter is important to ensure that the entire contents of the folder are copied as well.

Copying Files and Permissions

You have the option to transfer permissions when copying. This is done with the command:

cp -RP Papier/ Papier3/
Managing files and folders under Linux – Copying and moving made easy

Here, the -P parameter ensures that the rights of the files as well as the timestamps are preserved, which can be particularly useful if you are copying from another user.

Renaming Files

Renaming files also occurs using the MV command. If you want to rename a file called "DOO" to "toOO", you use:

mv DOO toOO
Managing files and folders in Linux – Copying and moving made easy

The principle is the same here: the file is moved from its original name to the new location with the new name. Similarly, you can also rename folders. For example, you would rename "Papier 3" to "Papier 100" with:

mv Papier3 Papier100
Managing files and folders under Linux – Copying and moving made easy

Summary – Managing Files and Folders in Linux

In this guide, you have learned how to efficiently copy, move, and rename files and folders in Linux. The key to effectively handling these tasks lies in the CP and MV commands as well as in managing wildcards and options.

Frequently Asked Questions

How do I create a new folder in Linux?Use the command mkdir to create a new folder.

How do I copy a folder including its contents?Use the command cp -R to copy the folder recursively.

What does the wildcard () mean in commands?The wildcard () stands for any characters and allows you to address multiple files at once.

Can I retain file permissions when copying?Yes, by using the -P parameter with the copy command, the permissions and timestamps of the files will be preserved.

What happens if I rename a file with the MV command?The MV command moves the file to a new name, which works like a rename.