Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 找到一个.txt文件并写入其中_Linux_Shell_Find - Fatal编程技术网

Linux 找到一个.txt文件并写入其中

Linux 找到一个.txt文件并写入其中,linux,shell,find,Linux,Shell,Find,我想知道是否有可能在一个目录及其子目录中找到多个.txt文件并在其中写入内容。差不多 find . -depth -type d -path "/path/to/files/*.txt" -exec echo > *.txt; 我设法创建了这样的文件,但现在我想把它们都写进去 提前感谢。我想用一个例子来回答: 要将“blablubb”写入中的每个文件(和子目录),请执行以下操作: 你可以写一个find-执行…或xargs: me@my:/tmp$ find . -maxdepth 2 -

我想知道是否有可能在一个目录及其子目录中找到多个.txt文件并在其中写入内容。差不多

find . -depth -type d -path "/path/to/files/*.txt" -exec echo > *.txt;
我设法创建了这样的文件,但现在我想把它们都写进去


提前感谢。

我想用一个例子来回答:

要将“blablubb”写入中的每个文件(和子目录),请执行以下操作:

你可以写一个
find-执行…
xargs

me@my:/tmp$ find . -maxdepth 2 -regex '.*txt' | xargs -I{} sh -c "echo 'blablubb' >> {}" 

me@my:/tmp$ find . -maxdepth 1 -regex '.*txt' -exec cat {} \;
blablubb
blablubb
blablubb
blablubb
blablubb

在这里可以找到更多信息:

一旦你找到一个txt文件,你想用它做什么还不是很清楚。@abhijitPritam编辑了我的帖子,谢谢你没有注意到
touch>文件
应该做什么@GéCusters我想你要找的是类似于
find/path/to/files/-name'*.txt'-exec sh-c'something>“{}”
,但是问题有点不清楚。@Biffen我编辑了我的帖子,它应该是
echo>文件
据我所知,它并不存在,但我想做一些类似的事情。谢谢你的帮助,我会尝试一下,让你知道它是否有效,或者我是否设法让它发挥作用
me@my:/tmp$ find . -maxdepth 2 -regex '.*txt' | xargs -I{} sh -c "echo 'blablubb' >> {}" 

me@my:/tmp$ find . -maxdepth 1 -regex '.*txt' -exec cat {} \;
blablubb
blablubb
blablubb
blablubb
blablubb