You are not logged in.

#1 2013-12-30 18:57:32

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

[Solved] List *only* contents of 7zip archive

I need to list only the contents (really, only the files would be preferable) of a 7zip archive. There doesn't seem to be a way to do this with the binary, so I'm wondering if anyone knows of any tried and true methods to do it with sed/awk/etc. In lieu of that, here's what I'm thinking:

The lines which describe files all begin with a four digit year

2013-12-30 12:18:28 ....A         8183               clang/ex9c

So I'd begin by getting just those lines with

awk '/^[0-9]{4}-/{print}'

Then I could filter out the directories based on the attribute field and print the files with {print NF}.

I would probably want to put all of this into one awk command. I've never tried anything like that before, can someone confirm that it's possible?

Last edited by alphaniner (2013-12-30 19:36:14)


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#2 2013-12-30 19:18:41

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Solved] List *only* contents of 7zip archive

Maybe other programs can do it? Try 'bsdtar ft <archivename>'.

Edit:

$ file 2.7z 
2.7z: 7-zip archive data, version 0.3
$ 7z l 2.7z 

7-Zip 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,1 CPU)

Listing archive: 2.7z

--
Path = 2.7z
Type = 7z
Method = LZMA
Solid = +
Blocks = 1
Physical Size = 164562
Headers Size = 183

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2013-12-30 20:11:40 ....A       163052       164379  2/11.jpg
2013-12-30 20:11:43 ....A       163052               2/12.jpg
2013-12-30 20:11:51 D....            0            0  2
------------------- ----- ------------ ------------  ------------------------
                                326104       164379  2 files, 1 folders
$ bsdtar ft 2.7z 
2/11.jpg
2/12.jpg
2/
$ bsdtar vft 2.7z 
-rw-r--r--  0 0      0      163052 Dec 30 20:11 2/11.jpg
-rw-r--r--  0 0      0      163052 Dec 30 20:11 2/12.jpg
drwxr-xr-x  0 0      0           0 Dec 30 20:11 2/

Last edited by karol (2013-12-30 19:26:23)

Offline

#3 2013-12-30 19:29:32

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: [Solved] List *only* contents of 7zip archive

Woot! Thanks, it (edit: specifically, bsdtar tf) works. I did not expect bsdtar to support 7zip archives. And directory listings end with / so I can easily filter them out too.

Last edited by alphaniner (2013-12-30 19:32:23)


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

Board footer

Powered by FluxBB