unzip解压当前目录下多个zip文件到指定目录

目的:解压PicFile下的所有zip文件到PicFiles下

[root@cmdiFile PicFiles]# unzip -d /mnt2/shanxi/PicFiles /mnt2/shanxi/PicFile/*.zip  
Archive:  /mnt2/shanxi/PicFile/P-WX-20170808-00005.zip
caution: filename not matched:  /mnt2/shanxi/PicFile/P-WX-20170808-00006.zip
caution: filename not matched:  /mnt2/shanxi/PicFile/P-WX-20170808-00007.zip
caution: filename not matched:  /mnt2/shanxi/PicFile/P-WX-20170808-00008.zip
caution: filename not matched:  /mnt2/shanxi/PicFile/P-WX-20170808-00009.zip
caution: filename not matched:  /mnt2/shanxi/PicFile/P-WX-20170808-00010.zip
caution: filename not matched:  /mnt2/shanxi/PicFile/P-WX-20170808-00011.zip
caution: filename not matched:  /mnt2/shanxi/PicFile/P-WX-20170808-00012.zip

使用 unzip -d /mnt2/shanxi/PicFiles /mnt2/shanxi/PicFile/*.zip命令报错,然后尝试写脚本执行

#!/bin/bash
#解压文件
#
for i in `ls /mnt2/shanxi/PicFile/`
do
unzip $i -d /mnt2/shanxi/PicFiles/
done

报以下错误:

unzip:  cannot find or open P-WX-20170808-00005.zip, P-WX-20170808-00005.zip.zip or P-WX-20170808-00005.zip.ZIP.
unzip:  cannot find or open P-WX-20170808-00006.zip, P-WX-20170808-00006.zip.zip or P-WX-20170808-00006.zip.ZIP.
unzip:  cannot find or open P-WX-20170808-00007.zip, P-WX-20170808-00007.zip.zip or P-WX-20170808-00007.zip.ZIP.
unzip:  cannot find or open P-WX-20170808-00008.zip, P-WX-20170808-00008.zip.zip or P-WX-20170808-00008.zip.ZIP.
unzip:  cannot find or open P-WX-20170808-00009.zip, P-WX-20170808-00009.zip.zip or P-WX-20170808-00009.zip.ZIP.

后来将命令改为: unzip -d /mnt2/shanxi/PicFiles '/mnt2/shanxi/PicFile/*.zip',执行成功,原因是系统将多个zip文件认为是在一个文件中,所以会报错。

 

你可能感兴趣的:(unzip解压当前目录下多个zip文件到指定目录)