search by tags

for the user

adventures into the land of the command line

working with compressed files

three commonly used compression utilities are zip, tar and gzip
files that have been compressed with these utilities will look like

zippedfile.zip
tarballfile.tar
gunzippedfile.gz
gunzippedtarballfile.tgz
gunzippedtarballfile.tar.gz

create a zip archive containing all files of the current directory

$ zip archive *

create a zip archive including all files starting with ’.’

$ zip archive .* *

to zip up an entire directory and all subdirectories into a file called archive.zip

$ zip -r archive directory

unzip a zip archive into the current directory

$ unzip archive.zip

unzip a zip archive into another directory

$ unzip archive.zip -d /tmp

create a tarball archive containing all the files in the current directory and subdirectories

$ tar -cvf archive.tar *

create a tarball archive containing separate directories and files

$ tar -cvf archive.tar dir1/ dir2/ file1 file2

create a compressed tarball archive containing separate directories and files

$ tar -czvf archive.tgz dir1/ dir2/ file1 file2

extract a tarball archive to the current directory

$ tar -xvf archive.tar

extract a tarball archive to another directory

$ tar -xvf archive.tar -C /tmp

extract a compressed tarball archive to another directory

$ tar -xzvf archive.tgz -C /tmp

compress a file

$ gzip -c file.txt > file.gz

compress a directory

$ gzip -cr directory > file.gz

uncompress to the current directory

$ gzip -d file.gz

uncompress to another directory

$ gzip -d file.gz > /tmp/file

more a compressed file without uncompressing it

$ zmore file.gz

cat a compressed file without uncompressing it

$ zcat file.gz

you can even pipe thru grep

$ zcat file.gz | grep something