方法一:
[root@vps zip]# ll
total 7240
-rwxr-xr-x 1 root root 2852 Jun 12 13:02 announcement.zip
-rwxr-xr-x 1 root root 7433 Jun 12 13:02 anti_spam_comment.zip
-rwxr-xr-x 1 root root 3530 Jun 12 13:02 antispam.zip
-rwxr-xr-x 1 root root 8382 Jun 12 13:02 digg.zip
-rwxr-xr-x 1 root root 3900 Jun 12 13:02 emlog2f5.zip
-rwxr-xr-x 1 root root 23821 Jun 12 13:02 emlog_sinat.zip
-rwxr-xr-x 1 root root 34089 Jun 12 13:02 face.zip
-rwxr-xr-x 1 root root 2494095 Jun 12 13:02 gvgu_image_watermark.zip
-rwxr-xr-x 1 root root 87278 Jun 12 13:02 kl_album.zip
-rwxr-xr-x 1 root root 30735 Jun 12 13:02 kl_auto_backup_and_mail.zip
-rwxr-xr-x 1 root root 3906 Jun 12 13:02 kl_auto_excerpt.zip
-rwxr-xr-x 1 root root 779 Jun 12 13:02 kl_blank.zip
-rwxr-xr-x 1 root root 9713 Jun 12 13:02 kl_data_call.zip
-rwxr-xr-x 1 root root 38308 Jun 12 13:02 kl_highslide.zip
-rwxr-xr-x 1 root root 29782 Jun 12 13:02 kl_sendmail.zip
-rwxr-xr-x 1 root root 2517 Jun 12 13:02 kl_set_navibar_sort.zip
-rwxr-xr-x 1 root root 4047 Jun 12 13:02 log_photo.zip
-rwxr-xr-x 1 root root 6553 Jun 12 13:02 note.zip
-rwxr-xr-x 1 root root 3257 Jun 12 13:02 ping.zip
-rwxr-xr-x 1 root root 4526272 Jun 12 13:02 posterip.zip
-rwxr-xr-x 1 root root 4409 Jun 12 13:02 qqt.zip
-rwxr-xr-x 1 root root 3293 Jun 12 13:02 related_log.zip
-rwxr-xr-x 1 root root 5205 Jun 12 13:02 sitemap.zip
-rwxr-xr-x 1 root root 13486 Jun 12 13:02 tag_cloud.zip
[root@vps zip]#
采用以下命令批量解压缩:
ls *.zip | xargs -n1 unzip
方法二:
ls *.zip | awk -F’.’’{print ” unzip ” $0 ” -x ” $1}’| sh
unzip 批量解压到指定目录下
在 yyy 目录下有很多.zip 文件,里面有个 xxx 目录,要把.zip 文件以本身文件名建一个目录 解压到 xxx 目录下。shell 脚本如下
for file in *.zip
do
filename=$(echo $file|cut -d’.’-f1)
unzip $file -d xxx/$filename
done
自己记录下。主要用到字符串变量处理,一开始想到,没想到用 sed cut grep awk 等。。