Bash 指定关键字时解压缩失败

Bash 指定关键字时解压缩失败,bash,unzip,Bash,Unzip,我需要解压缩与名称中特定关键字匹配的文件。典型的文件如下所示: JGS-Memphis~PSU~FVT~00000~JGM96911~1~P~1100~EPS10R0-15~CL10D1120A3271~0121017~141645.XML 当我这样做的时候 unzip -o SOMEFILE.zip '*~PSU~*' -d psutmp/ 它可以毫无问题地从SOMEFILE.zip解压上面的文件。但当我这么做的时候 for i in `find . -name '*zip'`; do

我需要解压缩与名称中特定关键字匹配的文件。典型的文件如下所示:

JGS-Memphis~PSU~FVT~00000~JGM96911~1~P~1100~EPS10R0-15~CL10D1120A3271~0121017~141645.XML
当我这样做的时候

unzip -o SOMEFILE.zip '*~PSU~*' -d psutmp/
它可以毫无问题地从
SOMEFILE.zip解压上面的文件。但当我这么做的时候

for i in `find . -name '*zip'`; do  unzip -o "$i" \'*PSU*\' -d psutmp/ ; done
它失败,文件名不匹配:“*PSU*”
错误。我试着去除PSU周围的记号。同样的问题

我还尝试了
-C
选项来无意识地匹配文件名大小写

for i in `find . -name '*XML*zip'`; do  unzip -o "$i" -C *PSU* -d psutmp/ ; done
它失败的原因是

error:  cannot create psutmp/JGS-Memphis~PSU~FVT~00000~JGM96911~1~P~1100~EPS10R0-15~CL10D1120A3271~0121017~141645.XML

这是铺位。我是一台拥有150GB存储空间的开发机器的root用户。容量为12%。我缺少什么?

删除
\'*P5U*\'
中的反斜杠。您不需要转义单引号

for i in `find . -name '*zip'`; do  unzip -o "$i" '*PSU*' -d psutmp/ ; done
在for循环中使用backticks有点代码味道。我会尝试以下其中一种:

# Unzip can interpret wildcards itself instead of the shell
# if you put them in quotes.
unzip -o '*.zip' '*PSU*' -d psutmp/

# If all of the zip files are in one directory, no need for find.
for i in *.zip; do unzip -o "$i" '*PSU*' -d psutmp/; done

# "find -exec" is a nice alternative to "for i in `find`".
find . -name '*.zip' -exec unzip -o {} '*PSU*' -d psutmp/ \;

就错误而言,
psutmp/
是否存在?是否设置了权限以便您可以对其进行写入?

删除
\'*P5U*\'
中的反斜杠。您不需要转义单引号

for i in `find . -name '*zip'`; do  unzip -o "$i" '*PSU*' -d psutmp/ ; done
在for循环中使用backticks有点代码味道。我会尝试以下其中一种:

# Unzip can interpret wildcards itself instead of the shell
# if you put them in quotes.
unzip -o '*.zip' '*PSU*' -d psutmp/

# If all of the zip files are in one directory, no need for find.
for i in *.zip; do unzip -o "$i" '*PSU*' -d psutmp/; done

# "find -exec" is a nice alternative to "for i in `find`".
find . -name '*.zip' -exec unzip -o {} '*PSU*' -d psutmp/ \;

就错误而言,
psutmp/
是否存在?是否设置了权限以便您可以对其进行写入?

find-名称'*.zip'-exec unzip-o{}'*PSU*'-d psutmp/\处理它。它实际上比循环更有效(不确定我在想什么…)。接受并投票通过。谢谢。
find-名称'*.zip'-exec unzip-o{}'*PSU*'-d psutmp/\处理它。它实际上比循环更有效(不确定我在想什么…)。接受并投票通过。非常感谢。