How to Use the Linux Terminal to Copy Files and Directories

HomeLatest NewsIoT

How to Use the Linux Terminal to Copy Files and Directories

Using the desktop interface, you may copy and paste files and directories (folders) in a Linux distribution, just like any other operating system. How

How to Clean Porch Screens for Spotless
Valuable Techniques for Dealing with Back Pain
Some guide for baby night light projector
Spread the love

Using the desktop interface, you may copy and paste files and directories (folders) in a Linux distribution, just like any other operating system. However, copying those files in the Terminal will save you time. Here’s how to do it.

1-Copy Directories and Files in Linux

cp and rsync are two of the most commonly used commands in Linux for fast copying files and directories. Both of them will be introduced to you.2-How to Use the cp Command. The command cp stands for copy and is used to copy files and directories in Linux. Copying files to a directory, copying one directory to another, and copying multiple files to a single directory are all possible using cp. Here are all of the examples that show how to use the cp command. Consider the syntax of cp in its most basic version.

Read More: What is AI Copywriting Software

The command above will copy the text file Test1.txt to the directory copy Test1 here/. If you need to copy numerous files to a single directory, simply list each file with a space between them. You can also save a file with a new name after copying it to a directory. The syntax for that is as follows. The contents of the first tile will be copied and saved in the directory as the new filename. This would be a real-life illustration of the same.

Given that a file named Test1.txt needs to be copied to the copy Test1 here directory as Test2.txt: Do you want to keep it in the same folder? You can rename a file by copying it and renaming it as follows: Do you want to copy a whole directory? Assume dir 1 and dir 2 are two directories in the Desktop directory. Here’s what you’ll need to input to copy dir 1 to dir 2 with the cp command.

Option -a denotes “archive” and is used to inform the computer that we’re working with directories. The command moves the dir 1 directory to dir 2.If you’re not sure whether a file or directory was transferred to the destination, use the -v option to report the names of the files and directories that were copied (like a computer programme output). Let’s pretend there’s a file called Test Example that needs to be transferred to dir 1. The -v option is used to show the output of the copy process. This is what the final product would look like:

3-How to Use the Rsync Command

The rsync command is used to move files and directories across machines on the same network. It does, however, allow you to copy files and folders between computers. Here are a few illustrations. We have two folders, dir 1 and dir 2, as well as the file Test.txt in dir 1. Here is what the rsync command would look like if we wanted to copy the file to dir 2.

The suffix -v stands for “verbose.” It works similarly to the -v option in the cp command in that it displays the details of the file transfer. This helps you to verify that the copy was completed successfully. In our situation, the outcome will be as follows: You can also copy numerous files from one directory to another at the same time. Assume you’re in /Desktop, where dir 1 and dir 2 are the two folders. You want to copy the files test1, test2, test3, and test4 from dir 1 to dir 2.This is how you can accomplish it with rsync:

Read More: 10 Best Skills to Learn For a Better Future in IT Industry

The files test1, test2, test3, and test4 will be copied to the dir 2 directory using the preceding command. The -a option is required to copy a directory from one location to another. Here’s an example of how to use Rsync to copy folders. If you’re new to Linux and find the commands difficult to understand, take your time and educate yourself with the basics first. The man command can also teach you a lot about commands. In addition to rsync and cp, the install command in Linux allows you to copy files.


Spread the love

COMMENTS