10 Ways to View the Content of Compressed Files under Linux Summary of of

  • 2021-07-06 12:24:20
  • OfStack

Generally speaking, when we view the contents of archived or compressed files, we need to decompress them first and then view them, which is troublesome. Today, I'll show you 10 different ways to easily view the contents of an archive or compressed file without extracting it.

Technically, it is impossible to view archived or compressed files without extracting them in advance. In the method described in this article, 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 emptied.

Before going into step 1, here we will explain archiving and compressing files under step 1.

Archiving is the process of combining multiple files or folders into one file. In this case, the generated file is not compressed. Compression is the result of compressing multiple files or folders into one file.

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

1. Use the Vim editor

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

$vim test. tar. gz replication code


" tar.vim version v29

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

test/imag.jpg
test/file.pdf
test/song.mp3
test/

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

To open a text file, simply use the arrow keys to move the cursor to the front of the file and press ENTER to open it

2. Use the tar command

The tar command can be used not only to compress/extract files, but also to view the contents of the compressed package using the tar-tf command without extracting the tar file.


$ tar -tf test.tar 

test/
test/image.jpg
test/file.pdf
test/song.mp3

Alternatively, use the-v option to view the detailed attributes of the archive file, 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 contents of the compressed package can be viewed using the rar v command 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 the unrar command

For the above rar file, you can also use the unrar command with l parameters 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

You can use the zip-sf command to view the contents of the zip file without extracting it.


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

test/imag.jpg
test/file.pdf
test/song.mp3
test/
0

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

test/imag.jpg
test/file.pdf
test/song.mp3
test/
1

6. Use the unzip command

Similar to unrar, use the unzip command with the-l parameter to view the contents of the zip file.


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

test/imag.jpg
test/file.pdf
test/song.mp3
test/
2

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.


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

test/imag.jpg
test/file.pdf
test/song.mp3
test/
4

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

test/imag.jpg
test/file.pdf
test/song.mp3
test/
5

8. Use the zcat command

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


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

test/imag.jpg
test/file.pdf
test/song.mp3
test/
6

The zcat and gunzip-c commands function the same. Therefore, you can also use the following command:


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

test/imag.jpg
test/file.pdf
test/song.mp3
test/
7

9. Use the zless command

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


$ zless test.tar.gz

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

10. Use the less command

The less command, which you probably know, allows you to view the contents of a file interactively. Not only that, but it can also be used to view the contents of archived/compressed files:


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

test/imag.jpg
test/file.pdf
test/song.mp3
test/
9

Summary

The above is a brief introduction to 10 different commands that allow you to view the contents of an archive/zip file without extracting it. If you are interested in some of these commands, you can delve into them yourself.


Related articles: