简体   繁体   English

如何解压缩到bash中的同一目录

[英]How to unzip to the same directory in bash

I have hundreds of directories, each containing several zip files. 我有数百个目录,每个目录包含几个zip文件。 I would like to iterate over each directory and unzip all zip files, placing the contents of the zip files into the same directory as the zip files themselves (without creating new sub-directories). 我想迭代每个目录并解压缩所有zip文件,将zip文件的内容放在与zip文件本身相同的目录中(不创建新的子目录)。 Here's the bash script I have: 这是我的bash脚本:

#!/bin/bash
src="/path/to/directories"
for dir in `ls "$src/"`
do
unzip "$src/$dir/*"
done

This script does the unzipping, but it creates thousands of sub-directories and dumps them on my desktop! 此脚本执行解压缩,但它会创建数千个子目录并将其转储到我的桌面上! How can I get the desired behavior? 我怎样才能获得理想的行为? I'm on Mac OSX if that makes a difference. 我在Mac OSX上,如果这有所作为。

#!/bin/bash

src=/path/to/directories
for dir in "$src"/*
do
    (cd "$dir" && unzip '*')
done

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

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