Ten methods of viewing compressed file content under Linux (summary)


Generally speaking, when we view the contents of the archived or compressed files, we need to decompress them first, and then view them, which is troublesome. Today, I’ll introduce you to 10 different ways to easily view the contents of archived or compressed files without decompressing.

Technically, it is impossible to view an archive or compressed file without decompressing it in advance. In the method described in this paper, these compressed files will be decompressed in a temporary directory / tmp in the background. After restarting the system, the contents of the / tmp directory will be cleared.

Before we go further, let’s explain archiving and compressing files.

  • Archiving is the process of combining multiple files or folders into one file. In this case, the generated file is not compressed.
  • Compression is a combination of multiple files or folders into a file and the result of compression file.

An archive is not a compressed file, but a compressed file can be an archive. After understanding these two concepts, we will formally introduce how to view the contents of compressed files without decompressing them.

1. Using VIM editor

VIM is not only an editor, it also contains many other powerful functions. The following command will directly display the contents of the compressed archive file:

$ vim test.tar.gz Copy code

" tar.vim version v29

" Browsing tarfile /home/alvin/test.tar.gz
" Select a file with cursor and press ENTER


Not only that, with VIM, you can even browse the archive directly. If there is a text file in it, you can also open it directly, which is very convenient.

If you need to open a text file, just use the arrow keys to move the cursor to the front of the file, and then press enter to open it

2. Use the tar command

The tar command can not only be used to compress / decompress files, but also to view the contents of compressed packages without extracting tar files.

$ tar -tf test.tar 


Alternatively, use the – V option to view the detailed properties of the archive, such as permissions, file owner, group, creation date, and so on.

$ tar -tvf test.tar

drwxr-xr-x alvin/users 0 2019-07-02 19:30 test/
-rw-r--r-- alvin/users 53632 2019-06-29 15:57 test/image.jpg
-rw-r--r-- alvin/users 156831 2019-06-04 12:37 test/file.pdf
-rw-r--r-- alvin/users 9702219 2019-04-25 20:35 test/song.mp3

3. Use the RAR command

Similarly, the RAR V command can be used to view the contents of the compressed package without extracting the rar file.

$ rar v test.rar

RAR 5.60 Copyright (c) 1993-2019 Alexander Roshal 24 Jun 2019
Trial version Type 'rar -?' for help

Archive: test.rar
Details: RAR 5

Attributes Size Packed Ratio Date Time Checksum Name
----------- --------- -------- ----- ---------- ----- -------- ----
-rw-r--r-- 53632 52166 97% 2019-06-29 15:57 70260AC4 test/image.jpg
-rw-r--r-- 156831 139094 88% 2019-06-04 12:37 C66C545E test/file.pdf
-rw-r--r-- 9702219 9658527 99% 2019-04-25 20:35 DD875AC4 test/song.mp3
----------- --------- -------- ----- ---------- ----- -------- ----
9912682 9849787 99% 3

4. Use Unrar command

For the rar file above, you can also use the Unrar command with the L parameter to view the contents of the rar file.

$ unrar l test.rar

UNRAR 5.60 freeware Copyright (c) 1993-2019 Alexander Roshal

Archive: test.rar
Details: RAR 5

Attributes Size Date Time Name
----------- --------- ---------- ----- ----
-rw-r--r-- 53632 2019-06-29 15:57 test/image.jpg
-rw-r--r-- 156831 2019-06-04 12:37 test/file.pdf
-rw-r--r-- 9702219 2019-04-25 20:35 test/song.mp3
----------- --------- ---------- ----- ----
9912682 3

5. Use the zip command

Without extracting the zip file, you can use the zip – SF command to view its contents.

$ zip -sf test.zip

Archive contains:
Life advices.jpg
Total 1 entries (597219 bytes)

6. Use unzip command

Similar to Unrar, use the unzip command with the – L parameter to view the contents of the zip file.

$ unzip -l test.zip

Archive: test.zip
Length Date Time Name
--------- ---------- ----- ----
597219 2019-04-09 12:48 Life advices.jpg
--------- -------
597219 1 file

7. Use the zipinfo command

To view the contents of the zip file, you can also use the zipinfo command.

$ zipinfo test.zip 

Archive: test.zip
Zip file size: 584859 bytes, number of entries: 1
-rw-r--r-- 6.3 unx 597219 bx defN 18-Apr-09 12:48 Life advices.jpg
1 file, 597219 bytes uncompressed, 584693 bytes compressed: 2.1%

8. Use zcat command

Use the zcat command to view the archive / compressed file.

$ zcat test.tar.gz

Zcat has the same function as gunzip – C. So you can also use the following command:

$ gunzip -c test.tar.gz

9. Use the zless command

Use the zless command to view the archive / compressed file.

$ zless test.tar.gz

Zless is similar to less in that it displays content page by page.

10. Use the less command

As you may know, less command can view the contents of files interactively. Not only that, it can also be used to view the contents of archived / compressed files:

$ less test.tar.gz


Here are 10 different commands that allow you to view the contents of the archive / compressed file without extracting the file. If you are interested in some of these commands, you can study them yourself.

The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.

Recommended Today

Practice of query operation of database table (Experiment 3)

Following the previous two experiments, this experiment is to master the use of select statements for various query operations: single table query, multi table connection and query, nested query, set query, to consolidate the database query operation.Now follow Xiaobian to practice together!Based on the data table (student, course, SC, teacher, TC) created and inserted in […]