![查找并执行:为什么这个命令不起作用?](https://linux22.com/image/49392/%E6%9F%A5%E6%89%BE%E5%B9%B6%E6%89%A7%E8%A1%8C%EF%BC%9A%E4%B8%BA%E4%BB%80%E4%B9%88%E8%BF%99%E4%B8%AA%E5%91%BD%E4%BB%A4%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8%EF%BC%9F.png)
我不明白为什么 echo 打印空行(最新的 cygwin 版本):
~/tmp >find mydor/ -name "*php"
mydor/es/c/packags.php
mydor/etns/inx.php
mydor/pacepors.php
mydor/XAE.php
~/tmp >find mydor/ -name "*php" -exec echo {} \;
~/tmp >find mydor/ -name "*php" -exec echo "{}" \;
~/tmp >find mydor/ -name "*php" -exec echo '{}' \;
~/tmp >
~/tmp >find --version
find (GNU findutils) 4.5.11
Packaged by Cygwin (4.5.11-1)
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2)
答案1
我确实找到了答案。这是我让它工作的方法(并且只有第一个成功时才可以连续执行 2 个进程,这是我在谷歌中找不到的解决方案):
find ./ -name "*php" -exec sh -c "sed 's/ \+ /\t/g' \"{}\" > tmpfile && mv tmpfile \"{}\"" \;