I am new to ubuntu. I have an error when using tar function along with gzip. I usee the following code :

find -type d -name 'doc*' | tar -czvf /path/where/gz/file/is/stored/file.tar.gz -T-

But the process begins, starts zipping and it is interupted in between showing this:

gzip: short write 
tar: write error: Broken pipe

and creates a empty tar.gz. How can I rectify this?

  • Does it happen with other compression algorithms, e.g. bzip2: tar -cj or xz: tar -cJ?
    – heemayl
    Oct 10, 2016 at 13:27
  • yes, it happens -cj .
    – kaya
    Oct 10, 2016 at 13:31
  • Does find -type d -name 'doc*' -exec tar -cvzf file.tar.gz {} + work?
    – heemayl
    Oct 10, 2016 at 13:36
  • i would like to clarify, if the command has to be like this : find -type d -name 'doc*' -exec tar -cvzf /path/to file.tar.gz { } +
    – kaya
    Oct 10, 2016 at 14:15
  • Yes, obviously.
    – heemayl
    Oct 10, 2016 at 14:31

2 Answers 2

tar -zcf /path/to/be/stored/file.tar.gz * 

This worked. But you have to be in the particular folder of the files to be gzipped


You're assuming that tar accepts a list of files to save from STDIN. It does not. See man tar and info tar.

A better way is, if your list of directories isn't too long, through command substitution:

tar -czvf /path/where/gz/file/is/stored/file.tar.gz \
    $( find . -type d -name 'doc*' -print)
  • 1
    It does, -T- is exactly for that.
    – heemayl
    Oct 10, 2016 at 13:26
  • using only tar was working well (but i still had doubling the size of the directory) though i got a tar file.
    – kaya
    Oct 10, 2016 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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