In my bash command line, when I use unzip -l test.zip I get the output like this:
Archive: test.zip Length Date Time Name --------- ---------- ----- ---- 810000 05-07-2014 15:09 file1.txt 810000 05-07-2014 15:09 file2.txt 810000 05-07-2014 15:09 file3.txt --------- ------- 2430000 3 files
But I am interested only by the lines containing the file details.
I tried to make filtering using grep like this:
unzip -l test.zip | grep -v Length | grep -v "----" | g -v Archive | grep -v " files"
But it is long and prone to error (e.g a file name Archive in this list will be dropped)
Is there any other options with unzip -l (I checked the unzip man page and did not find any) or another tool to do so?
It is important to me to not really unzip the archive but just to look what files are inside.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
zipinfo -1 file.zip
Or:
unzip -Z1 file.zip
Would list only the files.
If you still want the extra info for each file names, you could do:
unzip -Zl file.zip | sed '1,2d;$d'
Or:
unzip -l file.zip | sed '1,3d;$d' | sed '$d'
Or (assuming GNU head):
unzip -l file.zip | tail -n +4 | head -n -2
Or you could use libarchive‘s bsdtar:
$ bsdtar tf test.zip file1.txt file2.txt file3.txt
$ bsdtar tvf test.zip -rw-rw-r-- 0 1000 1000 810000 Jul 5 2014 file1.txt -rw-rw-r-- 0 1000 1000 810000 Jul 5 2014 file2.txt -rw-rw-r-- 0 1000 1000 810000 Jul 5 2014 file3.txt
$ bsdtar tvvf test.zip -rw-rw-r-- 0 1000 1000 810000 Jul 5 2014 file1.txt -rw-rw-r-- 0 1000 1000 810000 Jul 5 2014 file2.txt -rw-rw-r-- 0 1000 1000 810000 Jul 5 2014 file3.txt Archive Format: ZIP 2.0 (deflation), Compression: none
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0