假设我有一个文件夹“images”,其中有 0001.zip 到 9999.zip,我想将它们全部解压缩并将它们保存在具有其文件名的子文件夹中,例如,0001.zip 将被解压缩并保存到/0001,0002.zip将被解压并保存到/0002,我试着做
unzip '*.zip'
但这会提取当前文件夹中的所有文件。
你可以这样做:
for file in *.zip; do
dir=$(basename "$file" .zip) # remove the .zip from the filename
mkdir "$dir"
cd "$dir" && unzip ../"$file" && rm ../"$file" # unzip and remove file if successful
cd ..
done
或者,在一行上一起运行它:
for file in *.zip; do dir=$(basename "$file" .zip); mkdir "$dir"; cd "$dir"; unzip ../"$file" && rm ../"$file"; cd ..; done
如果您需要/想要保留原始 .zip 文件,只需删除该&& rm ../"$file"
位即可。
for zip in *.zip
do
unzip "$zip" -d "${zip%.zip}"
done