Fastest Way To Copy a Directory In Linux

cp, rsync, tar?

Basil A.
1 min readAug 8, 2020
Photo by Darren Nunis on Unsplash

Here are the three approaches mostly used for copying a directory on the same host from one folder (or partition) to another.

Suppose we have two folders, SOURCE_FOLDER and DESTINATION_FOLDER The three approaches for copying are:

Approach #1: Using cp

cp -R /path/to/SOURCE_FOLDER/* /path/to/DESTINATION_FOLDER/

Approach #2: Using rsync

rsync -a /path/to/SOURCE_FOLDER/ /path/to/DESTINATION_FOLDER

Approach #3: Using tar

cd /path/to/SOURCE_FOLDER; tar cf - . | (cd /path/to/DESTINATION_FOLDER; tar xvf -)

Copying a 2.5 GB directory on a Windows Subsystem Linux Ubuntu folder:

COMMAND              TIME TAKEN 
----------------------------------------------------------
cp 12.167 seconds
rsync 11.763 seconds
tar 8.125 seconds

tar surprisingly outperforms both cp and rsync by a huge factor.

tar consumes only ~67% the time cp takes, and ~69% the time rsync takes.

Hope this helps on your next partition migration.

--

--

Basil A.

A Software Engineer with interests in System Design and Software Engineering done right.