Peek Into Zip Files With Terminal 0

Terminal

Share
Peek Into Zip Files With Terminal

Hey

I tend to download a lot of zip files. I could use a Quicklook plugin such as zip viewer, but that is too easy. I want a bit of a challenge. Today’s post is about viewing the contents of a zip file in Terminal. This is quite handy if you are working in Terminal on a local or remote machine and want to view a zip files contents before you unzip the file. This trick will allow you to view the contents and write the contents to a text file.

The first step is to open up Terminal. Navigate to your zip file by using the “cd” command and typing in the path to your file. For example cd ./downloads, this file can be any any where on your Mac.

Here comes the magic bit, copy and past the following into Terminal.

unzip -l "$@" test.zip

Where text.zip is the name of you zip file you want to view. You need to have the at and dollar symbol for the text to be displayed on screen. You should have something similar to the image shown below.

inside zip files

Very handy where you can see the size of the file in bytes, the date is was created and the name and location of the file.

You can send the information found in the screen shot to a text file. You can use this to keep a log of a text file or as a backup to send to someone else. To forward the information to a text file type the following:

unzip -l "$@" test.zip > textfile.txt

You can append the data to the end of a text file by using to arrows “>>”. This will add what ever is found in the zip file to the end of the text file you select, great if you are making an archive of what is in text files.

Quite a useful tip, for some reason I can’t get it to work with multiple file. The unzip feature supports more than one archive, however it doesn’t seem to do anything if you want to display the contents. I’ll see if I can find a method, if I do i’ll post it here.

I cool little trick and tip, that you might want to use. This trick can be used to build upon scripts or code you are making.


If you want to keep up with the latests post from Mac Tricks And Tips I recommend you subscribe to the RSS Feed.

Where To Next?

  • Subscribe To Mac Tricks And Tips