bash 查找文件并执行命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26911213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find files and execute command
提问by Linuxxon
I have a lot of rar archives structured in individual folders and would like to script unpacking them all.
我有很多 rar 档案结构在单独的文件夹中,并且想要脚本解压它们。
I'm having trouble figuring out how it should be done and need some help.
我无法弄清楚应该如何完成并且需要一些帮助。
#!/bin/bash
## For all inodes
for i in pwd; do
## If it's a directory
if [ -d "$i" ] then
cd $i
## Find ".rar" file
for [f in *.rar]; do
./bin/unrar x "$f" # Run unrar command on filename
cd ..
done
done
done
I am not familiar with bash scripting and I assume the code is wrong more than once. But I guess this should be the basic structure
我不熟悉 bash 脚本,我认为代码不止一次出错。但我想这应该是基本结构
回答by hek2mgl
回答by jherran
You don't need a script.
你不需要脚本。
find . -name "*.rar" -exec unrar x {} \;
Additionally, you could pass the results of find to unrar
command.
此外,您可以将 find 的结果传递给unrar
命令。
find . -name "*.rar" | xargs unrar x