Pet*_*r.O 17 find text-processing filenames
像下面这样的东西就是我所追求的,但我的代码不起作用,无论我如何逃避{}
和+
;
find ./ -maxdepth 1 -type d -name '.*' -exec \
find {} -maxdepth 1 -type f -name '*.ini' -exec \
md5sum \{\} \\; \;
Run Code Online (Sandbox Code Playgroud)
在看到这个Unix-&-Linux question 后,我发现下面的代码有效,但它并没有嵌套find,我怀疑有更好的方法来完成这项特定的工作。
find ./ -maxdepth 1 -type d -name '.*' \
-exec bash -c 'for x; do
find "$x" -maxdepth 1 -type f -name "*.ini" \
-exec md5sum \{\} \;; \
done' _ {} \+
Run Code Online (Sandbox Code Playgroud)
有什么方法可以find -exec
在不需要调用 shell(如上)的情况下嵌套,以及所有古怪的引用和转义约束?
或者这可以直接在单个 find 命令中完成,使用它的许多参数的混合?
jw0*_*013 11
我会尝试使用单个查找,例如:
find .*/ -maxdepth 1 -type f -name '*.ini' -execdir md5sum {} +
Run Code Online (Sandbox Code Playgroud)
甚至(根本没有find
,只是shell globbing)
md5sum .*/*.ini
Run Code Online (Sandbox Code Playgroud)
尽管这缺少-type f
检查,因此仅当您没有以.ini
. 如果你这样做,你可以使用
for x in .*/*.ini; do
if [ -f "$x" ]; then
md5sum "$x"
fi
done
Run Code Online (Sandbox Code Playgroud)
然而,这将失去只需要一次 md5sum 调用的优势。
编辑
对于一般且安全的链接方法find
,您可以执行以下操作
find <paths> <args> -print0 | xargs -0 -I{.} find {.} <args for second find> [etc.]
Run Code Online (Sandbox Code Playgroud)