Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to check the file size of a tar.gz file without decompressing it under linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to check the file size of the tar.gz file under linux". In the daily operation, I believe that many people have doubts about how to check the file size of the tar.gz file without decompressing the tar.gz file under linux. The editor consulted all kinds of materials and sorted out a simple and useful method of operation. I hope it will be helpful to answer the question of "how to check the file size if you don't extract the tar.gz file under linux"! Next, please follow the editor to study!

How to check the file size without unzipping the tar.gz file

Tar tvf my_file.tar.gz

The output looks like:

-rwxr-xr-x root/root 2348366 2010-10-26 11:09:46 File_1.txt

-rwxr-xr-x root/root 2383552 2010-10-26 12:52:45 File_2.txt

-rw-r-r- root/root 89106866 2010-12-20 14:30:01 File_3.txt

The third column of data from the left is the file size (in bytes), and the sixth column is the file name. If you want to see more clearly, filter the output with awk:

Tar tvf my_file.tar.gz | awk'{print $3, $6}'

This outputs only columns 3 and 6, which looks like:

2348366 File_1.txt

2383552 File_2.txt

89106866 File_3.txt

If you want to display the file size in KB/MB/GB, you can divide N 1024 by column 3, for example, if you want to display as GB, then:

Tar tvf my_file.tar.gz | awk'{print $3amp 1024, $6}'

The number of bytes divided by 3 1024 is GB, and the output looks like:

0.00218708 File_1.txt

0.00221985 File_2.txt

0.0829872 File_3.txt

If you have a very large file (for example, hundreds of gigabytes) and there are many files in the package, the process will be long, so it is reasonable to let the shell command be executed in the background and output the results to a file, as follows:

Nohup tar tvf my_file.tar.gz | awk'{print $3amp 1024, $6}'> / root/result.txt &

Nohup is to ensure that the shell command is uninterrupted (when the network condition is poor, client software such as SecureCRT may break the connection with the server, so the command is interrupted before the command is finished), needless to say, the redirector is saved to the result.txt file in the / root/ directory.

At this point, the study of "how to check the file size of tar.gz files without decompression under linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report