Linux 用于在多个目录中提取文件名的命令

Linux command for extract file names in mutiple directories

我有多个后缀相同且文件名相同的目录。 假设我有如下文件。

~/test/sample1/test.txt
~/test/sample2/test.txt
~/test/sample3/test.txt
~/test/sample4/test.txt

我想做的只是将路径和文件名列表打印到一个 txt 文件中,所以我尝试了..

for t in ~/test/sample*/test/txt; do echo $t >> result.txt; done

但一无所获。

我怎样才能让它发挥作用?

谢谢!

您可以在此处使用查找命令。

转到要搜索的父目录并执行以下命令。

find . -name "test.txt" > result.txt

您的 "for t in ~/test/sample*/test/txt; do echo $t >> result.txt; done"

中的细微变化

"for t in ~/test/sample*/test.txt; do echo $t >> result.txt; done"

这应该适合你。

谢谢