Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Fedora 17 and bash as my shell. I have a specific zip file, which has just one folder in it's root. I.e. upon unpacking the zip file i see the following:

> unzip
> ls folderThatWasInsideZip

Supposing you know, that there is only 1 folder packed in the zip file, how do I find out the name of the main folder inside the zip file, without actually unpacking the zip file?

I'm looking for a one-liner, that would enable me to do something like this:

> <command>

I know there are ways to list all the files in the zip with less, but that lists all the files in the subdirectories etc. I just want to know the name of the one folder. I know I'm missing something basic..

share|improve this question
the -l option is used to list the files rather than unpack the zip file. see man unzip. – l1zard Nov 14 '12 at 9:18
up vote 2 down vote accepted

This command seems to do what you want:

unzip -qql | head -n1 | tr -s ' ' | cut -d' ' -f5-

Or with GNU sed:

unzip -qql | sed -r '1 {s/([ ]+[^ ]+){3}\s+//;q}'
share|improve this answer
That would give me the answer, but it unpacks the zip file. I need to do it without unpacking the zip as I'm writing in the question.. Is there a way? – Jan Hrcek Nov 14 '12 at 10:33
@JanHrcek: looking at gdb traces for unzip and unzip -l shows that inflate_block() function is not called with -l, i.e. the file is not decompressed, only meta data is read. – Thor Nov 14 '12 at 11:53
Yes, you're right :) Sorry. – Jan Hrcek Nov 14 '12 at 12:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.