100 Useful Command-Line Utilities
by Oliver; 201444. gzip, gunzip, bzip2, bunzip2
It's a good practice to conserve disk space whenever possible and unix has many file compression utilities for this purpose, gzip and bzip2 among them. File compression is a whole science unto itself which you can read about here.Zip a file:
$ gzip file(The original file disappears and only the .gz file remains)
Unzip:
$ gunzip file.gzBunzip:
$ bunzip2 file.bz2You can pipe into these commands!
$ cat file.gz | gunzip | head
$ cat file | awk '{print $1"\t"100}' | gzip > file2.gzThe first preserves the zipped file while allowing you to look at it, while the second illustrates how one may save space by creating a zipped file right off the bat (in this case, with some random awk).
cat a file without a unzipping it:
$ zcat file.gzless a file without a unzipping it:
$ zless file.gzTo emphasize the point again, if you're dealing with large data files, you should always compress them to save space.