Linux – Read the contents of a zipped file without extraction


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.

Best Answer

unzip -l 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 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.