I have some multi-layer organized compressed files, which are compressed in different methods. A sample structure looks like this (non compressed data files are omitted for simplicity).
A.zip
|---B.zip
| |-----C.zip
|---C.rar
|---D.tar.gz
How can I extract all files into a new folder and keep this structure unchanged? I have searched and get something like find . -depth -name '*.zip' -exec /usr/bin/unzip -n {} \; -exec rm {} \;
, but it only can uncompress *.zip
.
答案 0 :(得分:1)
您可以对每种文件类型使用该模式一次:
find . -depth -name '*.zip' -exec unzip -n {} \; -delete
find . -depth -name '*.tar.gz' -exec tar zxf {} \; -delete
find . -depth -name '*.rar' -exec unrar x {} \; -delete
当然,此解决方案遍历目标路径的次数与文件类型一样多,但它的好处很简单。
您可以使用单个find
来处理所有文件类型,但可读性会受到影响:
find . -depth \( -name '*.zip' -exec unzip -n {} \; -delete \) \
-o \( -name '*.tar.gz' -exec tar zxf {} \; -delete \) \
-o \( -name '*.rar' -exec unrar x {} \; -delete \)