yar*_*one 4 command-line archive unzip
我希望从文本列表中解压缩 ZIP 文件,将每个文件解压缩到自己的文件夹中,并将错误输出到日志文件中。
该列表如下所示:
0001.zip
0002.zip
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用以下命令,但我只是不知道如何完成上述操作。
find -name '*.zip' -exec sh -c 'unzip -d "${1%.*}" "$1"' _ {} \;
Run Code Online (Sandbox Code Playgroud)
谢谢你。
由于您已经有了提取命令sh -c 'unzip -d "${1%.*}" "$1"',您可以使用xargs将输入文件转换为参数:
xargs -a list-of-files -L1 sh -c 'unzip -d "${1%.*}" "$1"' _
Run Code Online (Sandbox Code Playgroud)
在{}没有必要的,因为xargs在默认情况下追加输入参数列表。这-L1使它使用一行输入作为参数。
然后只需将输出重定向到一个文件:
xargs -a list-of-files -L1 sh -c 'unzip -d "${1%.*}" "$1"' _ &> zip.log
Run Code Online (Sandbox Code Playgroud)
或者只是错误:
xargs -a list-of-files -L1 sh -c 'unzip -d "${1%.*}" "$1"' _ 2> zip.log
Run Code Online (Sandbox Code Playgroud)
如果我们假设您有一个 zip 文件的文本列表,例如:
zipfile1.zip
another_archive.zip
...
Run Code Online (Sandbox Code Playgroud)
那么你可以做
zipfile1.zip
another_archive.zip
...
Run Code Online (Sandbox Code Playgroud)
这将创建一个目录,将 zip 文件解压缩到其中,同时将所有内容写入与 zip 文件本身相同目录中的日志文件。