When I execute cp folder1 folder2 -rf
,for the first time it takes around 10 mins. But when it I execute the second command cp folder1 folder3 -rf
, it takes around 1 min. folder1
contains about 100 000 files.
Why is there run time improvement for the second time?
Between drives, 'mv' should essentially amount to cp + rm (copy to destination, then delete from source). On the same filesystem, 'mv' doesn't actually copy the data, it just remaps the inode, so it is far faster than cp.
When using a thumb drive with a persistent operating system, it happens that the persistent partition casper-rw gets corrupted, if one pulls out the thumb drive too early after shutting down the operating system.
rsync is much faster than cp for this, because it will check file sizes and timestamps to see which ones need to be updated, and you can add more refinements. You can even make it do a checksum instead of the default 'quick check', although this will take longer.
This is because of page caching. Run sync ; echo 3 > /proc/sys/vm/drop_caches
to make it slow again.
Further reading:
The first time the files are read from your hard drive.
The second time the files are read from memory.
Linux, as most operating systems, caches accessed files/blocks in memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With