Generally speaking, when we view the contents of archived or compressed files, we need to uncompress them first and then view them again, which is quite troublesome. Here are 10 different ways you can easily view the contents of an archive or compressed file without unzipping it.
It is technically impossible to view archived or compressed files without extracting them beforehand. The method described in this article unzips these compressed files in a temporary directory/TMP in the background. After the system restarts, the/TMP directory is cleared.
Before going any further, here’s an explanation of archiving and compressed files.
The archive
Is the process of combining multiple files or folders into a single file. In this case, the generated file is not compressed.The compression
Is a result file that is compressed by combining multiple files or folders into a single file.
An archive file is not a compressed file, but a compressed file can be an archive. With these two concepts in mind, let’s formally introduce how to view the contents of a compressed file without decompressing it.
1. Use Vim editor
Vim is more than just an editor, it also contains many other powerful features. The following command will display the contents of the compressed archive directly:
$ vim test.tar.gzCopy the 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/Copy the code
Not only that, but Vim allows you to browse through your archives directly, and if there’s a text file in there, you can open it, which is very convenient.
To open a text file, simply use the arrow keys to move the cursor in front of the file and press ENTER to open it
2. Run the tar command
The tar command is not only used to compress and decompress files, but also can be used to view the contents of the compressed package without extracting the tar file.
$ tar -tf test.tarCopy the code
test/
test/image.jpg
test/file.pdf
test/song.mp3Copy the code
Alternatively, use the -v option to view detailed properties of the archive, such as permissions, file owner, groups, creation date, and so on.
$ tar -tvf test.tarCopy the code
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.mp3Copy the code
3. Run rar
Similarly, the rar v command can be used to view the contents of compressed packages without extracting rar files.
$ rar v test.rarCopy the code
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 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 99% 3, 9912682, 9849787Copy the code
4. Run unrar commands
For the rar file above, you can also view the contents of the RAR file using an UNRar command with the L parameter.
$ unrar l test.rarCopy the code
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-3Copy the code
5. Run the zip command
You can use the zip-sf command to view the contents of a ZIP file without extracting it.
$ zip -sf test.zipCopy the code
Archive contains:
Life advices.jpg
Total 1 entries (597219 bytes)Copy the code
6. Run the unzip command
Similar to unrar, use the unzip command with the -l parameter to view the contents of a ZIP file.
$ unzip -l test.zipCopy the code
Archive: test.zip
Length Date Time Name
--------- ---------- ----- ----
597219 2019-04-09 12:48 Life advices.jpg
--------- -------
597219 1 fileCopy the code
7. Run the zipinfo command
To view the zip file contents, you can also use the zipinfo command.
$ zipinfo test.zip Copy the code
Archive: test.zip Zip file size: 584859 bytes, number of entries: 1-RW-r --r-- 6.3 unx 59789 bx defN 18-apr-09 12:48 Life advices. JPG 1 file, 59789 bytes uncompressed, 584693 bytes compressed: 2.1%Copy the code
8. Run the zcat command
Use the zcat command to view archive/compressed files.
$ zcat test.tar.gzCopy the code
Zcat has the same function as the gunzip -c command. Therefore, you can also use the following command:
$ gunzip -c test.tar.gzCopy the code
9. Run the zless command
Use the zless command to view archive/compressed files.
$ zless test.tar.gzCopy the code
Zless is similar to less in that it displays content page by page.
10. Run less
The less command, as you probably know, provides an interactive way to view the contents of a file. Not only that, it can also be used to view the contents of archived/compressed files:
$ less test.tar.gzCopy the code
summary
Here are 10 different commands that allow you to view the contents of archived/compressed files without extracting them. If you’re interested in some of these commands, delve into them for yourself. —————–
I am good xu, the world’s top 500 foreign companies Linux development engineer, specializing in the production of Linux dry goods. Welcome to pay attention to my public account “Liang Xu Linux”, which shared the Linux introduction, basic, advanced and other series of tutorials, but also Git, Vim, open source projects and other technical goods. Public number background reply “1024” to obtain the latest and most complete technical information, reply “into the group” into the master such as cloud technology exchange group.