Linux does not extract compressed files, how to directly view a file size

  

When doing Linux system operation, sometimes the compressed file is too large, it is inconvenient to decompress, if only one of the files is needed, Also want to know how big the file is, what should I do? The following small series will introduce you to how to view the size of the files under Linux without unpacking the tar.gz file. Let's learn together.

see how not unpack the files tar.gz file size

tar tvf my_file.tar.gz

output of the form:

-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 (unit : Byte), the sixth column is the file name. If you want to see more clearly, use awk to filter the output:

tar tvf my_file.tar.gz |  Awk ‘{print $3, $6}’

This will only output the 3rd and 6th columns, and the output will look like this:

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 the third column, for example, if you want to display GB, :

tar tvf my_file.tar.gz |  Awk ‘{print $3/1024/1024/1024, $6}’

The number of bytes is divided by 3 1024, which is GB, and the output is 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 G) and the archive contains many files, this The process will be lengthy, letting shell commands execute in the background, and it is a reasonable practice to output the results to a file, as follows:

nohup tar tvf my_file.tar.gz |  Awk ‘{print $3/1024/1024/1024, $6}& rsquo; 》 /root/result.txt &

nohup guarantees uninterrupted shell commands (secureCRT and other clients when network conditions are poor) The software may interrupt the connection with the server, so that the command has been interrupted before it is executed.) The redirection character is not necessary, and the result is saved to the result.txt file in the /root/directory.

The above is the way to view the file size in the compressed file under Linux. If you don't know how to view the file in the compressed file, you can try the method described in this article, I hope to help you.

Copyright © Windows knowledge All Rights Reserved