zip
It is possible to compress a file, for example, in this way:
zip mynewarchive mybigfile.txt
This creates a new file called mynewarchive.zip
that stores the contents of mybigfile.txt
but takes less room. After compressing the file, it is safe to remove the original file mybigfile.txt
. If you want to uncompress the zip
file and restore the original text file, you can run:
unzip mynewarchive.zip
Compressing files using the zip
utility can also be used for other types of files as well. Zipping text files is particularly effective, for instance, if the text file is in one language or if many phrases are repeated, because the zip
utility has the ability to remove many duplications and can use an efficient algorithm to save the file using a much smaller number of bytes.
Similarly, we can compress an entire directory of files (include any subdirectories) using the -r
option. (The -r
stands for "recursive".)
zip -r myrecipes recipe*.txt
This will compress, for instance, recipe1.txt
through recipe5.txt
into a new zipped file called myrecipes.zip
. We can retrieve the original uncompressed recipe files anytime by typing: unzip myrecipes.zip
.
Other compression utilities such as gzip
and tar
are also available. See, for instance, section 15.6 and section 15.7 of the Unix Power Tools book