Copy Files and Folders on AlmaLinux With 2 Easy Steps

This guide intends to teach you to Copy Files and Folders on AlmaLinux 8/9 with the cp and rsync commands. In simple words, copying files and folders means duplicating the contents to a new file. Also, you can copy the files for backup. Now let’s see what cp and rsync commands mean and the differences between them.

What Is CP Command?

The cp command is used for copying files from one location to another location. Also, it can be used to copy directories or folders.

What Is rsync Command?

rsync is a great tool that you can use to copy files and folders between local and remote systems.

What’s the difference between the cp command and the rsync command?

One of the most obvious differences between these commands is that rsync can be used to sync files remotely(machine to machine) while cp is only used to copy files from one directory to another on a single machine.

Also, rsync uses a delta transfer algorithm i.e. only changes are being copied while cp copies the entire file.

You can now follow the steps below provided by the Orcacore website to learn how to Copy Files and Folders on AlmaLinux 8/9.

Steps To Copy Files and Folders on AlmaLinux with cp and rsync

To Copy Files and Folders on AlmaLinux 8/9, you must have access to your server as a root or non-root user with sudo privileges. To do this, you can check the following AlmaLinux initial guides:

Initial Server Setup with AlmaLinux 8

Initial Server Setup with AlmaLinux 9

Copy Files and Folders on AlmaLinux with cp and rsync

Step 1 – How To Use cp Command on AlmaLinux?

As we said, the cp command is used for copying files and folders (directories). The syntax of the cp command is shown below:

cp [options] [source…] [destination…]

You can now use the cp command to Copy Files and Folders on AlmaLinux.

Copy a File with the cp Command on AlmaLinux

At this point, you can use the cp command to copy a file in another location. For example, you have a file named text_file1.txt in the temp directory and you want to copy this file to the temp2 directory. To do this, you can run the command below:

sudo cp ~/temp/text_file1.txt ~/temp2

This will copy the text_file1.txt file to the temp2 with the same name on AlmaLinux.

If you want to copy this file with a different name, you can use the command below:

sudo cp ~/temp/text_file1.txt ~/temp/text_file2.txt

This will copy the text_file1.txt file with the text_file2.txt in the current temp directory.

Copy Multiple Files with cp Command on AlmaLinux

At this point, if you have multiple files you want to copy. First, navigate to the directory where the files are saved with the command below:

sudo cd ~/temp

Then, use the cp commands with the names of the files and the destination path:

sudo cp text_file1.txt text_file2.txt text_file3.txt ~/temp2

Also, you can use the command below to copy all the files into a destination instead of the names:

sudo cp ~/temp/* ~/temp2

This will copy all the files in the temp directory to the temp 2 folder.

Step 2 – How To Use rsync Command on AlmaLinux?

At this point, you can use the rsync command to Copy Files and Folders on AlmaLinux. The syntax of the “rsync” command to copy files is shown below:

rsync [options…] [source…] [destination…]

This tool is pre-installed on AlmaLinux same as the cp command.

To copy a file from one place to another place with a different name you can use the command below. For example:

sudo rsync ~/dir1/file1.txt ~/dir2/text_file.txt

Also, you can copy all the files in a directory to another location by using the -a option. For example:

sudo rsync -a ~/dir1/ ~/dir2

This will copy all the files in the dir1 folder to the dir2.

If you want to copy the dir1 directory to the dir2, you can use the above command but without using / after dir1:

sudo rsync -a ~/dir ~/dir2

With this command, you have the dir1 directory in the dir2.

That’s it, you are done.

Conclusion

At this point, you have learned to Copy Files and Folders on AlmaLinux 8/9 by using the cp and rsync commands. You can easily use these Linux Commands to copy your files and directories.

Hope you enjoy it. You may also interested in these articles:

Install OpenCV on AlmaLinux 8

Execute .ps1 File on Linux Terminal

Fix cPanel Error ‘PHP PECL imagick fails on PHP 8.3’

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!