brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: unzip -Z1 prints only the file names of a zip, one per line

Shell
~/tips/tip-unzip-z1-names-only

unzip -Z1 photos.zip

Lists the names inside a zip file with no sizes or dates, ready for pipes and loops.

The normal unzip -l listing has a header, dates, sizes and a footer. That looks fine on screen and is annoying in a script, where you only want the names. The zipinfo mode of unzip has a switch for it.

unzip -Z1 photos.zip

-Z switches unzip to ZipInfo mode and -1 means file names only, one per line. The unzip help text describes it the same way. For a small archive it printed this:

photos/
photos/2026/
photos/2026/one.jpg
photos/two words.jpg

Compare that with unzip -l photos.zip, which wraps the same four names in a header with Length, Date and Time columns and a total line. The plain list is what you want for counting or filtering:

unzip -Z1 photos.zip | grep -c '\.jpg$'
unzip -Z1 photos.zip | grep '\.jpg$' | while IFS= read -r f; do printf '%s\n' "$f"; done

The first line printed 2 for this archive. The loop is written with IFS= read -r and quotes, because the name photos/two words.jpg has a space in it.

Caveats: folders are in the list too, as entries that end with a slash, so filter them out if you only want files. And a name with a newline in it would still break the loop, since the list is one name per line. Plain unzip -Z without the digit prints an ls -l style listing with the method and date, which is the better choice when you want a quick look at what is in there.

Further reading: Info-ZIP UnZip

More Shell tips zmv -n '(*).log' '$1.txt' zoxide query -ls project f=$(mktemp --suffix=.json) shopt globskipdots echo $EPOCHSECONDS All Shell tips (79) All topics

Link