如何检查zip文件中文件的长度

Ani*_*rni 1 bash shell zip unzip file-length

我想检查压缩文件中的文件是否为空。我知道该unzip -l命令,但它提供了很多信息。

[abc@localhost test]$ unzip -l empty_file_test.zip
Archive:  empty_file_test.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
    0      07-05-2017 06:43   empty_first_20170505.csv
    0      07-05-2017 06:43   empty_second_20170505.csv
---------                     -------
    0                         2 files
Run Code Online (Sandbox Code Playgroud)

我通过命令从zip文件中提取了文件名

file_names="$(unzip -Z1 empty_file_test.zip)
file_name_array=($file_names)
file1=${file_name_array[0]}
file2=${file_name_array[1]}
Run Code Online (Sandbox Code Playgroud)

我尝试使用-s选项,但没有用

if [ -s $file1 ]; then
   echo "file is non zero"
else
   echo "file is empty"    
fi
Run Code Online (Sandbox Code Playgroud)

file is empty即使文件不为空,也始终打印。

sjs*_*sam 5

unzip -l empty_file_test.zip | awk 'NR>=4{if($1==0){print $4}}'
Run Code Online (Sandbox Code Playgroud)

可能对您有用,也可以写成

unzip -l empty_file_test.zip | awk 'NR >= 4 && $1==0{print $4}'
Run Code Online (Sandbox Code Playgroud)