Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've a big sparse file ( about 100 GB that only 1 GB of it is used and it's .raw file )
I want to copy this file faster than normal copy with cp command,
Any one familiar with this concept?
My first reaction: Why would you want or need such a file?
Regardless, I'd assume that any action to compress the file before copying would take more time than simply copying it. But, if you need to copy it many times, then just compress it.
You could also try "dd", but I have no idea if it would be faster. Maybe try it on a smaller file.
I've a big sparse file ( about 100 GB that only 1 GB of it is used and it's .raw file )
I want to copy this file faster than normal copy with cp command,
Any one familiar with this concept?
I've a big sparse file ( about 100 GB that only 1 GB of it is used and it's .raw file )
I want to copy this file faster than normal copy with cp command,
Any one familiar with this concept?
Yes, the concept is called impatience ;-).
Do you need the bloat - the extra 99 Gig? If so, and you have another 30 or 40 gig for a temporary file, why not 'gzip sparse_file'. If you don't need the crap, give details on the stuff you want, and the stuff you want to leave behind.
You probably can't.
I just ran some tests, and "cp" appears to recognise sparse (input) files o.k. However strace shows it issuing a read every 32k. There is also a corresponding seek on the output fd.
All that takes time, even if the file is completely empty (as in my test).
Update: got me wondering now - how much benefit is there in that. A file of the same size full of random data issues the same number of reads, and issues writes in place of seeks. Takes much longer of course, but if a sparse file is (actually) zero bytes, why all the reads ...
Just for the post, try a race. I would suggest gzip -1, as you are not particularly pressed for space. You could also do a cron job to have the zipping done when you are at home :-D
I was thinking about this on the ride home. Looking at the manpage confirms that "cp" is only looking to see if a sparse output allocation is required.
I'll check rsync tomorrow.
excerpt from 'sparse file:copying';cp --sparse=always formerly-sparse-file recovered-sparse-file
It should be noted that some cp implementations do not support the --sparse option and will always expand sparse files, like FreeBSD's cp. A viable alternative on those systems is to use rsync with its own --sparse option[3] instead of cp.
'rsync --sparse' is viable alternative to the 'cp --sparse=always formerly-sparse-file recovered-sparse-file'.
O.K., some more testing showed the above "cost" for cp is all set-up of a new file. Repeated copies into the (pre-allocated) destination file showed minimal reads and writes.
Far better than rsync (-b -S) in fact. Both cp and rsync created a sparse output, but rsync continued to read and write the entire file when only a couple of sectors out of 1Gig had non-zero data. cp was much more efficient.
Similar results for 5 Meg input.
My test, my data, my machine, YMMV, <blah>, <blah>, <blah> ...
O.K., some more testing showed the above "cost" for cp is all set-up of a new file. Repeated copies into the (pre-allocated) destination file showed minimal reads and writes.
Far better than rsync (-b -S) in fact. Both cp and rsync created a sparse output, but rsync continued to read and write the entire file when only a couple of sectors out of 1Gig had non-zero data. cp was much more efficient.
Similar results for 5 Meg input.
My test, my data, my machine, YMMV, <blah>, <blah>, <blah> ...
So do you think normal use of cp is the best choice?
Yes - especially if you can re-use the output files each day (after the first obviously). That is, don't delete the (output) files each day, over-write them.
The "-b" on the rsync was *bad* - but even with "-t" (or -a), "cp" was still marginally faster. Which surprised me I must admit.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.