xyz*_*xyz 26 linux command-line
如何设法找到目录和子目录中的所有文件并对它们运行命令?
例如,
find . -type f -name "*.txt"
Run Code Online (Sandbox Code Playgroud)
查找所有 txt 文件并:
find . -type f -name "*.txt" | gedit
Run Code Online (Sandbox Code Playgroud)
将它发送到 gedit,但在文本文件中。我想让 gedit 打开所有文本文件。
Dav*_*ain 37
您可以使用该-exec标志对每个匹配的文件执行命令:
$ find ./ -type f -name "*.txt" -exec gedit "{}" \;
Run Code Online (Sandbox Code Playgroud)
语法有点奇怪(-exec command ;有关更多信息,请参见联机帮助页):
The string `{}' is replaced by the current file name being processed
Run Code Online (Sandbox Code Playgroud)
您可能还想考虑-execdir,它会做同样的事情,但是从包含匹配文件的子目录中执行命令(这通常是可取的)。
find . -type f -name "*.txt" -print0 | xargs -0 gedit