Fastest Way To Copy a Directory In Linux

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


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.

A Software Engineer with interests in data storage and database systems done right.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store