If you are flexible about the format, you can compress a file in Unix doing just that :-)
compress some_file
downside: you need to specify every single file to compress.
You can also use zip
, not always available on UNIX platforms, or gzip. While compress
and gzip
just compress a single file, zip
is a tool that handles packaging of one or many files or directories and compression all in one go. The traditional UNIX philosophy is to have one tool for one job, making it easier for the tool's creator to make the tool excel at that one job, explaining why compress and gzip only compress, and do not package. For you as a user that means you will use use one tool for packaging, and then another to compress the package (or "archive"), if you are not using zip, but UNIX native tar
, the tape archiver, to package first:
tar -c -f archive_name.tar some_file some_dir
will pack some_file
and some_dir
, recursively, in the archive archive_name.tar
.
now compress it:
gzip archive_name.tar
will give you the compressed file archive_name.tar.gz
(and delete the original archive_name.tar
).
But wait, there is more: it is actually so common to compress archives, that tar can call gzip, in one command:
tar -c -z -f archive_name.tar.gz some_file some_dir
will give you archive_name.tar.gz
, containing some_file
and some_dir
, packaged recursively, and compressed.
For more info:
man 1 tar
zip
output.