作者:wolveszhang_543 | 来源:互联网 | 2023-01-30 14:36
我想检查压缩文件中的文件是否为空。我知道该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
我通过命令从zip文件中提取了文件名
file_names="$(unzip -Z1 empty_file_test.zip)
file_name_array=($file_names)
file1=${file_name_array[0]}
file2=${file_name_array[1]}
我尝试使用-s
选项,但没有用
if [ -s $file1 ]; then
echo "file is non zero"
else
echo "file is empty"
fi
file is empty
即使文件不为空,也始终打印。
1> sjsam..:
unzip -l empty_file_test.zip | awk 'NR>=4{if($1==0){print $4}}'
可能对您有用,也可以写成
unzip -l empty_file_test.zip | awk 'NR >= 4 && $1==0{print $4}'