Copy Large Number of Files Using The Terminal

Copy Large Folders Easily!

In this article, we’ll learn how to copy a large number of files using the terminal. Copying files and folders can be a hassle if you have them in a large amount. And it puts stress on your system resources too.

However, traditional GUI copying mechanisms have been slow because of the extra resource that particular GUI apps require. Linux has several command line tools through which you can copy a large file or a folder very easily and hassle-free.

In this article, we are going to discuss various methods and tools through which you can copy large amount of files and folders easily.

Easy Ways to Copy Large Number of Files using Terminal

Let’s now take a look at the different tools you can use to copy a large number of files using the terminal.

1. RSync

Rsync is a fast, reliable tool that can be used to copy data either locally from one folder to another or copy from/to another connected machine that is connected to your machine via ssh. It saves time by updating the files instead of completely rewriting them if, for example, you have two different versions of the same file in your source and destination. Here’s how you can use this command :

rsync -a {Source}/ {Destination}/

For example,

rsync -a /home/aadesh/Documents /home/aadesh/videos

This command will copy all the files from my Documents folder to the Videos folder. However, if you want to know the progress of the process, you can add -v which will state the file names which are being copied.

Rsync Av Output
rsync -av Output

2. cp Command

The cp command in Linux is the most basic way through which you can copy files from one place to another. This command is also compatible with ssh and can transfer data from/to connected remote machines.

Here’s how to use it:

cp /file/source.txt /destination/folder

However, if you have a folder inside the source directory, you should use -r

cp -r /file/source.txt /destination/folder

You can also add -v option, and it will list the filenames as they are being copied.

cp -rv /folder/to/be/copied /Copy/destination
Cp Rv Command Output
cp -rv Command Output

And if you are not sure that few files that are being copied from the source are already in the destination folder, you can add -i to use the interactive mode, it will then ask you what to do if two files with the same name exists in both the folders.

cp -rvi /folder/to/be/copied /Copy/destination
Cp Command Interactive Option
cp Command Interactive (-i) Option

If you don’t want to overwrite existing files in the destination folder, add -n option to the cp command.

cp -rnv /folder/to/be/copied /Copy/destination

-u option can be useful to you, this option of cp command will allow you to update the destination file, if the source has a newer version of the file.

cp -ruv /folder/to/be/copied /Copy/destination
Only Modified Poem File Is Transferred
Only Modified Poem File Is Transferred

3. Compress the files

If you think that compressing and extracting the files will take less time than the whole transfer process, then you should follow this method. We’ll use the tar command to compress a folder :

tar -zcvf archive-name.tar.gz /directory/to/be/compressed
Compressing Sample Folder
Compressing Sample Folder

After the compression, transfer the file by using either cp or rsync and then once the compressed file is copied to the destination, use this command to extract :

tar -zxvf archive-name.tar.gz
Extracting Compressed File After Copying
Extracting Compressed File After Copying

Conclusion

We hope you have learned different methods through which you can copy large files from one location to another. You can also transfer files from/to remote machines connected to you via ssh, but in that case, the transfer speed will depend on your Internet connection.