UNIX File Compression

Check

To show the content directory of a zip file...

zipinfo myzipfile.zip

unzip -l myzipfile.zip

vim myzipfile.zip

less myzipfile.zip

To show more detail about a zip file...

zipdetails myzipfile.zip

Compress

To compress a single file and store it in a zip archive...

zip myzipfile.zip myfile.txt

To compress the contents of a directory and store it in a zip archive...

zip -r myzipfile.zip mydir/

To compress the contents of a directory and split the zip archive into 5m chunks...

zip -r -s 5m myzipfile.zip mydir/

This will give you files called myzipfile.z01, myzipfile.z02... with a final file called myzipfile.zip

To compress the files newer than a particular file (myfile,.txt) from a directory (mydir) and its subdirectories...

(where myfile.txt has a timestamp of 01-Jan-2023 00:00)

touch -d "20230101" myfile.txt

zip mydir.zip $(find mydir -newer myfile.txt)

Uncompress

To uncompress a single zip file relative to the current working directory...

unzip myzipfile.zip

To uncompress a split archive...

zip -F myzipfile.zip --out myrecombined.zip

unzip myrecombined.zip

View

unzip -p myzipfile.zip file1.txt | less

zcat mygzipfile.gz

bzcat mybzfile.bz

zmore mygzipfile.gz

zless mygzipfile.gz

View Images

Bibliography