简体   繁体   English

如何使用 shell 脚本解压缩目录中的所有文件?

[英]How to unzip all files in directory using shell script?

I want to unzipped all the files from the specific directory but dont know how to do it using shell script.我想解压缩特定目录中的所有文件,但不知道如何使用 shell 脚本。

Lgl_Entitiy.txt.zip
Lgl_Entitiy.txt_1.zip
Lgl_Relate.txt.zip
Lgl_Relate.txt_1.zip
Lgl_Name.txt.zip
Lgl_Name.txt_1.zip

Install unzip:安装解压:

sudo apt install unzip or yum install unzip sudo apt install unzip 或yum install unzip

Use this in the same directory you want to unzip the files:在要解压缩文件的同一目录中使用它:

unzip ‘*.zip’

If you want to put the uncompressed files in other directory, then use this:如果要将未压缩的文件放在其他目录中,请使用以下命令:

unzip ‘*.zip’ -d /usr/sampleZip/ExampleDir

To put it into a shell script:将其放入 shell 脚本中:

vim shellscript.sh

Then the script could be something like:那么脚本可能是这样的:

#!/bin/bash

unzip ‘*.zip’

After saving the script, to execute it:保存脚本后,执行它:

./shellscript.sh

you can use simple unzip command.您可以使用简单的解压缩命令。

Let me give you an example:让我给你举个例子:

  1. go into the directory where you have the zip files. go 进入您拥有 zip 文件的目录。
cd /home/rexter/test
  1. there are few zip files in this location.此位置几乎没有 zip 文件。
ls

1.zip
2.zip
3.zip
  1. now if you want to unzip them all just type:现在,如果您想将它们全部解压缩,只需键入:
unzip '*.zip'

And its done!它完成了!

######################## ########################

As you want script for the same.正如你想要的脚本一样。 Here it is just edit accordingly这里只是相应地编辑

#!/bin/bash

cd <path-to-your-directory>

unzip '*.zip'

save this file as unzipscript.sh and give executable permission to it using 'sudo chmod +x unzipscript.sh' and then run this script.将此文件保存为 unzipscript.sh 并使用 'sudo chmod +x unzipscript.sh' 为其授予可执行权限,然后运行此脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM