Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a tree of directories with files like this:

|-- 00
|   |-- 00
|   |   |-- 00
|   |   |-- 01
|   |   |-- 02
|   |   |-- 03
|   |   |-- 04
|   |   |-- 05
|   |   |-- 97
|   |   |-- 98
|   |   `-- 99
|   |-- 01
|   |   |-- 00
|   |   |-- 01

There is about 200 files at the end of each directory, so a lot of files. What would be the fastest way of making a tar.gz of the whole thing? Can I parallelize the task for many CPUs?

share|improve this question
The bottleneck will be disk I/O, not CPU. Unless you have lots of small files on a RAID-1 device, you won't gain anything by parallelizing. – Gilles Jun 28 '11 at 12:40
up vote 3 down vote accepted

On ext[234] filesystems, I find dump to be much faster than tar, especially with many small files, like a Maildir. It also uses multiple cores for concurrent compression. I suggest using -b 1024 for a 1mb block size, which works much better than the default 10kb block size.

share|improve this answer

You only need to specify one (or more) the top level directory(s) to include, and tar will recursively dip into all it's children and wrap everything up:

tar cvfz output.tar.gz /path/to/top_folder

(As @forcefsck notes if the object is raw speed you can leave off the v option for less verbosity on the terminal. By not echoing every file it adds you save a little bit if I/O time talking to your terminal.)

share|improve this answer
change cvfz to zcf. verbose output slows the process and f must be at the end so it is immediately followed by the archive filename. – forcefsck Jun 28 '11 at 5:44
@forcefsck: You are right that the OP could leave off v, but unless the files are tiny it usually doesn't affect things that much and allows you to see that it did what you expected, which this OP needs to see. As for f, you are wrong, it does not need to be last. Try for yourself. Flags may come in any order as long as the next argument is the file name. In my head compression arguments like z and j makes a lot more sense that way. – Caleb Jun 28 '11 at 6:14
about f, yes I am wrong :( somehow I remembered a case that it needed to be last. I guess my memory failed me. About v, the OP asked the fastest way and we do need to consider the case of many small files. – forcefsck Jun 28 '11 at 7:24
@forcefsck: I edited my answer to not the speed consideration. Arugment order matters, the filename has to be the next argument, but arguments are separated by spaces. The wad of cvfz is a different syntax of flags. I think if you use the -c -v -z -f filename syntax you would have to do those in order. BSD's tar might only accept that syntax, I can't remember. However I have seen a lot of tutorials using my syntax but insisting f had to be last, which simply isn't the case. – Caleb Jun 28 '11 at 7:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.