找到-exec与多个命令 [英] find -exec with multiple commands
问题描述
我试图使用find -exec有没有任何成功多个命令。是否有人知道,如下面的命令是可能的吗?
I am trying to use find -exec with multiple commands without any success. Does anybody know if commands such as the following are possible?
find *.txt -exec echo "$(tail -1 '{}'),$(ls '{}')" \;
基本上,我想打印在当前目录和打印每个txt文件的最后一行在该行,逗号后的文件名末尾。
Basically, I am trying to print the last line of each txt file in the current directory and print at the end of the line, a comma followed by the filename.
推荐答案
找到
也将接受多个 -exec
部分的命令:
find
will also accept multiple -exec
portions to the command:
find . -name "*.txt" -exec echo {} \; -exec grep banana {} \;
请注意,在这种情况下,第二个命令将只在第一个成功返回时,运行由@Caleb提及。如果你想,无论其成功或失败的两个命令来运行,你可以使用此结构:
Note that in this case the second command will only run if the first one returns successfully, as mentioned by @Caleb. If you want both commands to run regardless of their success or failure, you could use this construct:
find . -name "*.txt" \( -exec echo {} \; -o -exec true \; \) -exec grep banana {} \;
这篇关于找到-exec与多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!