Back to the blog

Files

Gzip one file, and what the terminal would do.

Make a .gz of one file in your browser, with nothing uploaded, its name and date kept, and see how it compares with gzip -k and tar -czf.

By 5 min read

One file packed into a .gz beside a terminal running gzip on the same file

Some places want a single file as .gz: a log, a database dump, a sitemap, a data file for an import. KeepSimp makes one in your browser, as gzip itself would. Here is how, and where it differs from gzip and tar on a terminal.

Gzip a file in your browser.

Open Gzip a file and drop one file on it. Press Make the .gz, and download it: report.csv becomes report.csv.gz. The page says how large it came out, and your file is left as it was.

A .gz holds exactly one file. Drop several and the page says so: to pack more than one, make a tar.gz or a ZIP instead.

Under More options, How hard to pack sets the level: 1 is quickest, 9 smallest and slowest. It starts at 6, gzip's own default.

What gzip -k does on a terminal.

`gzip -k report.csv` writes report.csv.gz and keeps report.csv. Without -k, gzip replaces the file with its .gz. Like the page, it saves the file's name and date in the .gz unless told not to with -n, and packs at level 6 unless given -1 to -9. `gzip a b c` makes three .gz files, never one archive: the gzip manual calls gzip a complement to tar, not a replacement.

The .gz files are the same kind either way and open with `gunzip`, 7-Zip or this page. The bytes inside may differ slightly, since two gzip programs can pack the same file differently at the same level; what comes out when it is unpacked is identical.

On a terminal
gzip -k report.csv      # report.csv.gz, report.csv kept
gzip -9 -k report.csv   # smallest, slowest
gzip -n -k report.csv   # no name or date inside
gunzip -k report.csv.gz # unpack it again

Where the page and gzip differ.

Names: RFC 1952 says the name in a .gz header is in ISO 8859-1, which holds Western European letters. The page writes names that way. A name with letters outside it, such as Japanese, emoji or Polish ł, is left out of the header and a note says so; the .gz file's own name still carries it. Gzip on a terminal writes the name's bytes as they are, which other tools may show wrongly.

The page has no switch for -n: the name and date are always kept. And it writes a new file rather than replacing yours, as gzip -k does. For very large files, or many of them in a script, the terminal is quicker and can be automated; the page is for when there is no terminal to hand, or the file should not leave your device.

When you need tar -czf instead.

`tar -czf site.tar.gz site/` puts a folder into a tar and gzips the tar in one go. GNU tar and bsdtar keep each file's owner, group and permissions, and store links as links. On a Mac, bsdtar also adds ._ files for extended attributes unless `COPYFILE_DISABLE=1` is set.

Create a tar.gz on this site makes the same kind of file from what you drop, with fixed permissions (0644 for files, 0755 for folders), owner 0, no links and nothing a Mac adds. That is what most uploads and imports want. When owners and permissions must be kept exactly, as for a backup of a server, use tar on that machine.

On a terminal
tar -czf site.tar.gz site/   # c: create, z: gzip, f: this file
tar -tzf site.tar.gz         # list what is inside
tar -xzf site.tar.gz         # take it all out

Further reading

Topics: gzip a file online · gzip file · make gz file · compress to gz · gzip -k · tar -czf · gzip online · gzip compression level

A little less theory. A little more doing.

Try it on your own terms, with a free browser tool.

Try the tool