It is also possible to decompress it using standard shell-script + gzip, if you don't have, or want to use openssl or other tools.
The trick is to prepend the gzip magic number and compress method to the actual data from zlib.compress
:
printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" |cat - /tmp/data |gzip -dc >/tmp/out
Edits:
@d0sboots commented: For RAW Deflate data, you need to add 2 more null bytes:
→ "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x00"
This Q on SO gives more information about this approach. An answer there suggests that there is also an 8 byte footer.
Users @Vitali-Kushner and @mark-bessey reported success even with truncated files, so a gzip footer does not seem strictly required.
@tobias-kienzler suggested this function for the bashrc:
zlipd() (printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" |cat - $@ |gzip -dc)
You can just do:
gzip *
gzip will tell you it skips the files that already have a .gz
ending.
If that message gets in the way you can use:
gzip -q *
What you tried did not work, because gzip
doesn't read the filenames of the files to compress from stdin, for that to work you would have to use:
ls | grep -v gz | xargs gzip
You will exclude files with the pattern gz
anywhere in the file name, not just at the end.¹ You also have to take note that parsing the output of ls
is dangerous when you have file names with spaces, newlines, etc., are involved.
A more clean solution, not relying on gzip
to skip files with a .gz
ending is, that also handles non-compressed files in subdirectories:
find . -type f ! -name "*.gz" -exec gzip {} \;
¹ As izkata
commented: using .gz
alone to improve this, would not work. You would need to use grep -vF .gz
or grep -v '\.gz$'
. That still leaves the danger of processing ls
' output
Best Answer
Yes. I use in-kernel initrd and it offers at least the following methods:
EDIT: You can use it on external file and with LZMA (at least on ubuntu).
EDIT 2: Wikipedia states that Linux kernel supports gzip, bzip and lzma (depending, of course, what algorithms are compiled in).