266

How can I read the contents of a particular file in an archive without extracting the .zip it is contained within? I'm using the Linux command line.

An earlier question asks about viewing the directory of the archive. But for me it is not enough to see just a list of the files in the archive, I need to see the contents of a file in the archive.

kasperd
  • 2,931
Shrikanth
  • 2,661
  • 2
  • 15
  • 3

8 Answers8

336

unzip -l archive.zip lists the contents of a ZIP archive to ensure your file is inside.

Use the -p option to write the contents of named files to stdout (screen) without having to uncompress the entire archive.

unzip -p archive.zip file1.txt | less

For this kind of operation I always pipe the output to less, otherwise the whole file goes flying up the screen before you can read it.

BTW zcat is great for viewing the contents of .gz files without having to uncompress them first.

Edit: Changed this answer to use -p instead of -c. -p extracts the file byte-for-byte, while -c prints the filename and may do EOL conversion. Also, unzip -p lets you extract multiple files, but it does not output in the order given like cat does.

Joey Adams
  • 2,318
13

You can use vim to list content of the zip/rar/tar archive:

vim archive.zip

BTW: here is the same question.

patryk.beza
  • 1,661
10

zipinfo is another tool you might use, this is useful if you're on a locked-down system where unzip is not allowed.

Jens Erat
  • 18,485
  • 14
  • 68
  • 80
Nickolai
  • 201
4

If you're just looking to view images inside the archives, you can use Comix or newer MComix to see images inside .zip, .rar, .cbr, and .cbz files without extracting.

Kokizzu
  • 1,807
2

Start Emacs in command-line and open your zip files with Zip-Archive mode. Without any Emacs/elisp tuning (new users generally fear about), you will see file details like from zipinfo: modes, length, date, time

Then, you will be able to open files in buffers and even save your changes back to archive, with standard shortcuts:

  • Enter on a file name in list to open it
  • Edit and save with Ctrl-x Ctrl-s
  • Kill buffer Ctrl-k to go back to archive buffer and go on

When in Zip-Archive buffer, use Ctrl-h m to get all shortcuts available in Help View.

Hope this may lead you to discover Emacs awesome features

1

A better way is just using zmore or zless, for example

zmore syslog.2.gz
zx485
  • 2,337
-1

I've found less archive.zip to be the easiest way to do this.

-1

If the file is included in zip archive, that you need to extract only that file from archive (may depend on archive type, some archives can't extract files seperately)

blogger
  • 590