4

less command on Ubuntu allows to peek inside different kinds of archives from terminal. For example, all of these commands would show me the list of files in each of the four archives:

less archive.zip
less archive.tar.gz
less archive.tar.bz2
less archive.7z

On MacOS, I can use vim for this. However, this is less convenient, because Vim requires four buttons to be pressed to exit it (:q + return) instead of one (q).

Is there an equivalently fast way to see list of files in archives for MacOS?

3

Manually

  • zip: unzip -v FILE.zip
  • tar.gz: tar tvzf FILE.tar.gz
  • tar.bz2: bunzip2 -c FILE.tar.bz2 | tar tvf -
  • .7z: 7z l FILE.7z

PS: For .7z you need to run brew install p7zip first

Extend less to work the same way it does under Linux

  • Install lesspipe

    brew install lesspipe
    
  • Add the following lines to .bashrc (or the profile of whatever shell you use)

    if [[ -x /usr/local/bin/lesspipe.sh ]]; then
        export LESSOPEN="|/usr/local/bin/lesspipe.sh %s"
        export LESS_ADVANCED_PREPROCESSOR=1
    fi
    
  • Source .bashrc or open a new terminal tab

3

MacOS Finder allows viewing the names of the files in a ZIP archive without extracting. But, since it takes more than three clicks to do it, perhaps this is not what you want.

How to do it. Mojave 10.14.5
In the Finder, select the ZIP file.
ready.zip
Hit the space bar. You see a window about the ZIP file.
mage In that window, click on the little triangle ▶︎ to see the list of files contained in the archive.
image
If there are folders within folders, use the new triangle to see them.
image

I haven't tried this with other types of archives. Of course, if the ZIP is encrypted, you may see less about it.

  • This shows a little window with two buttons, but no triangle there... MacOS 10.14.5 Mojave. – Andriy Makukha Jul 17 at 14:19
  • 1
    It my interface this window looks different. The button on the right is called "Uncompress". And on the left I see a giant icon of an archive. But no way to press it and see the tree. – Andriy Makukha Jul 17 at 15:00
  • Interesting. So maybe this interface is supplied by "The Unarchiver", which is free in the Mac App Store. Maybe you have to set The Unarchiver as the default way to open ZIP files? – GEdgar Jul 17 at 15:06
  • Maybe. My default is "Archive Utility". – Andriy Makukha Jul 17 at 15:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .