Check the file size in the tar.gz file.

Source: Internet
Author: User
For more information, see How to decompress the tar.gz file in the linuxlinuxsystem to view the file size.

If you do not want to decompress the tar.gz file to view the file size

Tar tvf my_file.tar.gz


Output format:
-Rwxr-xr-x root/root 2348366 11:09:46 File_1.txt
-Rwxr-xr-x root/root 2383552 12:52:45 File_2.txt
-Rw-r-root/root 89106866 14:30:01 File_3.txt

The third column from the left is the file size (in bytes), and the third column is the file name. To make it clearer, use awk to filter the output result:
Tar tvf my_file.tar.gz | awk '{print $3, $6 }'
In this way, only 3rd and 6th columns are output, as shown in the following figure:

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 use 3rd columns except N 1024. for example, if you want to display the file size as GB, then:
Tar tvf my_file.tar.gz | awk '{print $3/1024/1024/1024, $6 }'
The number of bytes is 1024, which is GB. the output format is as follows:
0.00218708 File_1.txt
0.00221985 File_2.txt
0.0829872 File_3.txt

If a large file (for example, a hundred GB) is contained in a compressed package, this process will take a long time for shell commands to be executed in the background, it is reasonable to output the result to a file, as follows:
Nohup tar tvf my_file.tar.gz | awk '{print $3/1024/1024/1024, $6}'>/root/result.txt &
Nohup ensures that shell commands are not interrupted (when the network conditions are poor, client software such as SecureCRT may interrupt the connection to the server, and the commands will be interrupted before being executed ), not to mention the redirection character. The final result is saved to the result.txt file in the/root/directory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.