10 ways to view compressed file contents in Linux (summary)

10 ways to view compressed file contents in Linux (summary)

Generally speaking, when we view the contents of an archived or compressed file, we need to decompress it first and then view it, which is rather troublesome. Today I will show you 10 different methods that will allow you to easily view the contents of archived or compressed files without decompressing them.

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

Before going further, here is an explanation of archive and compressed files.

  • Archiving is the process of combining multiple files or folders into a single file. In this case, the resulting file is not compressed.
  • Compression is the process of combining multiple files or folders into one file and compressing the resulting file.

An archive file is not a compressed file, but a compressed file can be an archive file. 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 just an editor, it also contains many other powerful features. The following command will directly display the contents of a compressed archive file:

$ vim test.tar.gzCopy 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, using Vim you can even browse archive files directly. If there is a text file in it, you can 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 press ENTER to open it.

2. Using tar command

The tar command can not only be used to compress/decompress files, but you can also use the tar -tf command to view the contents of the compressed package 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 detailed properties 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 rar command

Similarly, you can use the rar v command to view the contents of the compressed file 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 above rar file, 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

You can view the contents of a zip file without extracting it using the zip -sf command.

$ 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 a 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 zipinfo command

To view the contents of a 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. Using zcat Command

Use zcat command to view archived/compressed files.

$ zcat test.tar.gz

zcat has the same functionality as the gunzip -c command. Therefore, you can also use the following command:

$ gunzip -c test.tar.gz

9. Use zless command

Use zless command to view archived/compressed files.

$ zless test.tar.gz

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

10. Use less command

Everyone may be familiar with the less command, which can view file contents in an interactive way. Not only that, it can also be used to view the contents of archived/compressed files:

$ less test.tar.gz

summary

The above briefly introduces 10 different commands that allow you to view the contents of archived/compressed files without extracting the files. If you are interested in some of these commands, you can slowly study them yourself.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • gzip command in linux
  • Several methods and viewing methods of data compression under Linux (sample code)
  • How to install JDK 13 in Linux environment using compressed package
  • Summary of Linux xz compression and decompression methods
  • Analysis of the method of uploading zip compressed packages under Windows to Linux system using compression
  • Detailed explanation of zip compression and unzip decompression commands and their usage in Linux
  • How to compress a folder in Linux
  • Linux gzip command compression file implementation principle and code examples

<<:  Detailed explanation of MySQL basic operations (Part 2)

>>:  In-depth understanding of JavaScript callback functions

Recommend

How to install and configure Docker nginx

Download Nginx image in Docker docker pull nginx ...

HTML tutorial, HTML default style

html , address , blockquote , body , dd , div , d...

Detailed explanation of how to install MariaDB 10.2.4 on CentOS7

CentOS 6 and earlier versions provide MySQL serve...

How to Understand and Identify File Types in Linux

Preface As we all know, everything in Linux is a ...

Introduction to MyCat, the database middleware

1. Mycat application scenarios Mycat has been dev...

MySQL 8.0 can now handle JSON

Table of contents 1. Brief Overview 2. JSON basic...

SQL ROW_NUMBER() and OVER() method case study

Syntax format: row_number() over(partition by gro...

Detailed Analysis of or, in, union and Index Optimization in MySQL

This article originated from the homework assignm...

Steps to build the vite+vue3+element-plus project

Use vite to build a vue3 project You can quickly ...

Implementation steps of mysql master-slave replication

Table of contents mysql master-slave replication ...

Detailed example of inserting custom HTML records in Quill editor

It is already 2020. Hungry humans are no longer s...

Docker Compose network settings explained

Basic Concepts By default, Compose creates a netw...

MySQL 5.6.27 Installation Tutorial under Linux

This article shares the installation tutorial of ...

Docker removes abnormal container operations

This rookie encountered such a problem when he ju...