Is there a multi-threaded cp
command on Linux?
I know how to do this on Windows, but I don't know how this is approached in a Linux environment.
Is there a multi-threaded cp
command on Linux?
I know how to do this on Windows, but I don't know how this is approached in a Linux environment.
As Celada mentioned, there would be no point to using multiple threads of execution since a copy operation doesn't really use the cpu. As ryekayo mentioned, you can run multiple instances of cp
so that you end up with multiple concurrent IO streams, but even this is typically counter-productive. If you are copying files from one location to another on the same disk, trying to do more than one at a time will result in the disk wasting time seeking back and forth between each file, which will slow things down. The only time it is really beneficial to copy multiple files at once is if you are, for instance, copying several files from several different slow, removable disks onto your fast hard disk, or vice versa.
Well, I believe you could use gnu parallel to accomplish your task.
seq 70 | parallel -j70 cp filename
You could see a detailed explanation on using gnu parallel from my other answer here.
I just tested the above command in my system and I could see that 70 copies of files are being made.
cp -R
). I'm copying many, many files between two disks, and this allows my disk read go from 15 MB/s to 150 MB/s. For example, ls lotsofdirs | parallel -j32 --progress cp -R lotsofdirs/{} /mnt/somedisk/lotsofdirs/{}
(make sure to mkdir -p /mnt/somedisk/lotsofdirs
first)
– allidoiswin
Jan 02 '23 at 12:49
The closest thing to a multithreaded process is the &
which runs commands in the background.
So to use this command, you would do something like:
cp file location &
cp
is IO-bound, I'm not sure how much multithreading would help. – Celada Oct 31 '14 at 15:08cp
could be a duplicate of a question aboutdd
... – maxschlepzig Nov 01 '14 at 09:28