15

This answer and this one suggest p7zip to work with 7zip-archives under Linux. I can see option for compressing and decompressing. But how can I get a content-listing of an archive, without decompressing it?

3 Answers 3

16

You need the 7z executable which comes from the p7zip-full package.

7z l archive.7z

lists the content

Source: 7z --help

2
  • 1
    The p7zip package does not have an executable called 7z.
    – Dennis
    Commented Nov 29, 2011 at 17:06
  • 3
    Oh, I see. It comes from p7zip-full.
    – choroba
    Commented Nov 29, 2011 at 17:48
9

The executable p7zip of the package p7zip does not have this function.

If you install p7zip-full, you can use the executable 7z which does.

7z -h shows you the basic syntax.

1

My bash scriptie could help you out...

#!/bin/bash

TITLE="7z - ARCHIVE INFO"
echo -en "\033]0;$TITLE\a" # Window Title

clear

echo "$TITLE"

echo

echo "Place this script in a dir with 7z files..."

echo

echo "Name of specific 7z-archive or of all 7z-archives?"

read -e -i "*.7z" -p ""  ZNAME

echo

echo "Password (EMPTY/ENTER = NO PW)?"

read -e -p "" PW

pw(){
if [[ $PW == "" ]]  
then
echo ""
else
echo "-p$PW"
fi
}

echo

echo "Just a moment..."

# CODE
for f in ${ZNAME}; do echo "${f}:"; echo -e "$(7z l -ba $(pw) "${f}")\n"; done > 0000_7z_ARCHIVEINFO.txt

# l = list contents of archive
# -ba = short version of archive.

echo

echo "Achive info has been written to file 0000_7z_ARCHIVEINFO.txt" 

echo

read

It should result in sth like this in file 0000_7z_ARCHIVEINFO.txt:

file1.7z:
data data data data data file1.pdf
data data data data data file1.txt

file2.7z:
data data data data data file2.pdf
data data data data data file2.txt

It simply shows you the name of each 7z and of all the files within. Usable for a single 7z-archive or for multiple 7z-archives (in the same dir). You could further trim it by piping the '7z -l -ba' command to the cut command and cut the first 5 'data' fields (date, time etc) with that (or keep the 6th field only, namely purely the file names). Or, some other method. Make it recursive etc. The password function in case your files are password protected (all with the same password in case of multiple files). Or leave it empty if no password required. Possibly flush your history after having inserted password(s) in terminal ;-)

Sorry for this lengthy thing, but maybe it gives ideas...

P.S.:

  • If you let the name of my script start with '0000', like '0000_7z_ARCHIVEINFO.sh', it will stay on top of the other files in the dir.
  • Beware that 7z flips on spaces in file names! You could add this code on top, somewhere after '$TITLE', to automatically replace all spaces by underscores in all file names (why not, also the none-7z's) first:

find . -depth -name "*" -execdir rename 's/[[:space:]]/_/g' {} ;

  • Don't use spaces in the file names within the 7z's either.
  • Just: NO SPACES!

You must log in to answer this question.

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