Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get file name and total count in zip (Linux)

Tags:

unix

How do I get result will have file names at beginning total #count of files. When I run a command line below only shows number of files but not file names.

I would like to have zip file name and count number of documents in zip. Thanks

the output:

IAD1.zip 30000 files
IAD2.zip 24000 files
IAD3.zip 32000 files
.....

command line

zipinfo IAD${count}.zip |grep ^-|wc -l >>TotalCount.txt

with command above the result show number of documents in zip files:

30000
24000
32000
.....
like image 945
thichxai Avatar asked Mar 13 '20 17:03

thichxai


People also ask

How do I find out how many records are in a Zip file?

You can try using "gunzip -c | wc -l" in input parameter with shell interpretation and use that value in graph . The use of 'wc -l' is only applicable if the file has a newline delimiter.

How do I count how many files are in a folder in Linux?

The easiest way to count files in a directory on Linux is to use the “ls” command and pipe it with the “wc -l” command. The “wc” command is used on Linux in order to print the bytes, characters or newlines count. However, in this case, we are using this command to count the number of files in a directory.

How do I list the contents of ZIP files in Linux?

To list/view the contents of a compressed file on a Linux host without uncompressing it (and where GZIP is installed), use the "zcat" command.

How many files can be in a Zip file?

For reference purposes, with the Zip64 extension to the Zip file format enhancement, Zip files of 16 exabytes, which is over 16 billion gigabytes (or 2 to the 64th power bytes) are possible. Likewise, over 4 billion files and folders can be included in a Zip file.


1 Answers

 zipinfo  -h <file name>  |  tr '\n' ':'  | awk -F':'  '{print $2 , $5 , "files"}'

explanation:

zipinfo  -h -- list header line.  The archive name, actual size (in bytes) and total number of files is printed.

tr '\n' ':' --  Replace new line with ":" 

awk -F':'  '{print $2 , $5 , "files"}' -- Read file as ":" delimited and print 2nd and 5th field

Demo:

:>zipinfo test.zip 
Archive:  test.zip
Zip file size: 2798 bytes, number of entries: 7
-rw-r--r--  3.0 unx       18 tx stor 20-Mar-10 13:00 file1.dat
-rw-r--r--  3.0 unx       32 tx defN 20-Mar-10 13:00 file2.dat
-rw-r--r--  3.0 unx       16 tx stor 20-Mar-10 12:26 file3.dat
-rw-r--r--  3.0 unx     1073 tx defN 20-Mar-12 05:24 join1.txt
-rw-r--r--  3.0 unx      114 tx defN 20-Mar-12 05:25 join2.txt
-rw-r--r--  3.0 unx      254 tx defN 20-Mar-11 09:39 sample.txt
-rw-r--r--  3.0 unx     1323 bx stor 20-Mar-14 09:14 test,zip.zip
7 files, 2830 bytes uncompressed, 1746 bytes compressed:  38.3%
:>zipinfo  -h test.zip  |  tr '\n' ':'  | awk -F':'  '{print $2 , $5 , "files"}'
  test.zip  7 files

like image 163
Digvijay S Avatar answered Dec 09 '22 15:12

Digvijay S