Easy Ways to Read/View Zip & Archive File Contents Without Extracting

Many of us know, how to zip, tar & unzip the files but few of them only knows how to Read the contents of a zipped file without extracting. In some cases you don’t want to extract the file but you want to view the file contents or list of the files which is there inside archive.

Most of the server logs are zipped to save disk space. Due to low disk space, you have to view the file without extract. is it possible? If yes, how?

Is it possible to view all kind of log files without extracting such as tar, tar.gz, tar.bz, tar.bz2, etc.,

I have more scope about zip command also adding few information about others too. We can easily read the contents of a zipped file without extracting also can view list of files on it.

Suggested Read : How To Use Zip & Unzip Commands In Linux/Unix

When we have a single file in the zip, we can use zcat, zless, zmore commands but if you have more than one files in the zip this commands won’t work, then what are the other options to view the particular file contents alone?

This is a small geek but more useful for us when we running out of space.

How to Read a files contents without extracting

By default most of the peoples unzip the zipped file to read the file contents but we have many option to get override. This will natively work when it has a single file and through errors for more than one files.

Read the file contents using zcat command.

# zcat magesh.zip
How to view/Read the contents of a zipped file without extracting

Read the file contents using zmore command.

# zmore magesh.zip
------> magesh.zip <------
How to view/Read the contents of a zipped file without extracting

Read the file contents using zless command.

# zless magesh.zip
How to view/Read the contents of a zipped file without extracting
magesh.zip (END)

How to View list of files in ZIP archive without extracting

To view list of files in ZIP archive without extracting, use the following command.

Use basic less command to view list of files in ZIP archive without extracting.

# less latest.zip
Archive:  latest.zip
Zip file size: 8722409 bytes, number of entries: 1617
drwxr-xr-x  3.0 unx        0 bx stor 17-Mar-06 09:00 wordpress/
-rw-r--r--  3.0 unx    16250 tx defX 16-Nov-28 22:39 wordpress/wp-settings.php
-rw-r--r--  3.0 unx     3286 tx defX 15-May-24 11:26 wordpress/wp-cron.php
-rw-r--r--  3.0 unx     1627 tx defX 16-Aug-29 06:00 wordpress/wp-comments-post.php
-rw-r--r--  3.0 unx     5447 tx defX 16-Sep-27 15:36 wordpress/wp-activate.php
drwxr-xr-x  3.0 unx        0 bx stor 17-Mar-06 09:00 wordpress/wp-admin/
-rw-r--r--  3.0 unx     2401 tx defX 16-Oct-23 22:45 wordpress/wp-admin/link-parse-opml.php
drwxr-xr-x  3.0 unx        0 bx stor 17-Mar-06 09:00 wordpress/wp-admin/js/
-rw-r--r--  3.0 unx    12188 tx defX 17-Feb-20 20:42 wordpress/wp-admin/js/editor.js
-rw-r--r--  3.0 unx     6224 tx defX 16-Nov-02 23:40 wordpress/wp-admin/js/user-profile.min.js
-rw-r--r--  3.0 unx     1508 tx defX 15-Jul-27 05:19 wordpress/wp-admin/js/word-count.min.js
-rw-r--r--  3.0 unx     5148 tx defX 16-Nov-17 11:28 wordpress/wp-admin/js/tags-suggest.js
-rw-r--r--  3.0 unx     6850 tx defX 17-Mar-06 06:16 wordpress/wp-admin/js/tags-box.js

Alternatively we can use the famous text editor called vim to view list of files in ZIP archive without extracting.

# vim latest.zip

Use the native zipinfo command to view list of files in ZIP archive without extracting.

# zipinfo latest.zip

How to Read a specific file contents from a zip archive without extracting

As we discussed in the first session, it will through error message when we have more than one file in the zip. See the below error message.

# zcat latest.zip
gzip: latest.zip has more than one entry--rest ignored

Use the following unzip command with -p option to view the particular file contents.

# unzip -p latest.zip wordpress/wp-config-sample.php

/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the
 * installation. You don't have to use the web site, you can
 * copy this file to "wp-config.php" and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * MySQL settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://codex.wordpress.org/Editing_wp-config.php
 *
 * @package WordPress
 */

grep particular string from a zip archive without extracting

In Linux everything is possible and nothing is impossible like that way we can gerp the particular string (Matching contents) from zipped file without extracting. See the below example.

# zgrep "Apr 14" /var/log/secure-20170416.gz
Apr 14 01:06:34 2daygeek sshd[7860]: pam_unix(sshd:session): session closed for user magi
Apr 14 01:07:20 2daygeek sshd[17174]: Accepted password for magi from 103.5.134.167 port 37751 ssh2
Apr 14 01:07:20 2daygeek sshd[17174]: pam_unix(sshd:session): session opened for user magi by (uid=0)
Apr 14 07:04:44 2daygeek sshd[17174]: pam_unix(sshd:session): session closed for user magi 
Apr 14 07:07:20 2daygeek sshd[10755]: Accepted password for magi from 103.5.134.167 port 40887 ssh2
Apr 14 07:07:20 2daygeek sshd[10755]: pam_unix(sshd:session): session opened for user magi by (uid=0)
Apr 14 08:45:59 2daygeek sshd[18386]: Accepted password for daygeek from 103.5.134.167 port 52972 ssh2

How to View list of files in tar archive without extracting

Use native tar command option to view list of files in tar archive without extracting.

$ tar -tvf omnirun.tar 
drwxr-xr-x magi/magi         0 2017-05-22 13:14 omnirun/
-rw-r--r-- magi/magi       519 2017-05-22 13:14 omnirun/.gitignore
-rw-r--r-- magi/magi        69 2017-05-22 13:14 omnirun/pyvenv.cfg
drwxr-xr-x magi/magi         0 2017-05-22 13:14 omnirun/omnirun/
-rw-r--r-- magi/magi        41 2017-05-22 13:14 omnirun/omnirun/__main__.py
-rw-r--r-- magi/magi      1810 2017-05-22 13:14 omnirun/omnirun/tmux.py
-rw-r--r-- magi/magi         0 2017-05-22 13:14 omnirun/omnirun/__init__.py
-rw-r--r-- magi/magi        20 2017-05-22 13:14 omnirun/omnirun/version.py
-rwxr-xr-x magi/magi     12560 2017-05-22 13:14 omnirun/omnirun/main.py
-rw-r--r-- magi/magi       180 2017-05-22 13:14 omnirun/.travis.yml
drwxr-xr-x magi/magi         0 2017-05-22 13:14 omnirun/tests/
-rw-r--r-- magi/magi       673 2017-05-22 13:14 omnirun/tests/test.py

To View list of files in tar.gz archive without extracting.

$ tar -tvf go1.8.linux-amd64.tar.gz
drwxr-xr-x 0/0               0 2017-02-17 00:59 go/
-rw-r--r-- 0/0           33243 2017-02-17 00:57 go/AUTHORS
-rw-r--r-- 0/0            1366 2017-02-17 00:57 go/CONTRIBUTING.md
-rw-r--r-- 0/0           45710 2017-02-17 00:57 go/CONTRIBUTORS
-rw-r--r-- 0/0            1479 2017-02-17 00:57 go/LICENSE
-rw-r--r-- 0/0            1303 2017-02-17 00:57 go/PATENTS
-rw-r--r-- 0/0            1399 2017-02-17 00:57 go/README.md
-rw-r--r-- 0/0               5 2017-02-17 00:57 go/VERSION
drwxr-xr-x 0/0               0 2017-02-17 00:57 go/api/
-rw-r--r-- 0/0             521 2017-02-17 00:57 go/api/README
-rw-r--r-- 0/0           20194 2017-02-17 00:57 go/api/except.txt

To View list of files in tar.bz2 archive without extracting.

$ tar -tvf go1.8.linux-amd64.tar.bz2
drwxr-xr-x 0/0               0 2017-02-17 00:59 go/
-rw-r--r-- 0/0           33243 2017-02-17 00:57 go/AUTHORS
-rw-r--r-- 0/0            1366 2017-02-17 00:57 go/CONTRIBUTING.md
-rw-r--r-- 0/0           45710 2017-02-17 00:57 go/CONTRIBUTORS
-rw-r--r-- 0/0            1479 2017-02-17 00:57 go/LICENSE
-rw-r--r-- 0/0            1303 2017-02-17 00:57 go/PATENTS
-rw-r--r-- 0/0            1399 2017-02-17 00:57 go/README.md
-rw-r--r-- 0/0               5 2017-02-17 00:57 go/VERSION
drwxr-xr-x 0/0               0 2017-02-17 00:57 go/api/
-rw-r--r-- 0/0             521 2017-02-17 00:57 go/api/README
-rw-r--r-- 0/0           20194 2017-02-17 00:57 go/api/except.txt

You may also like...

Shares
Close
Please support the site
By clicking any of these buttons you help our site to get better