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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.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
Shell 用于在多个目录中提取文件名的Linux命令_Shell_Command - Fatal编程技术网

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

Shell 用于在多个目录中提取文件名的Linux命令,shell,command,Shell,Command,我有多个具有相同后缀且包含相同文件名的目录。 假设我有如下文件 ~/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 但是什么都没有 我怎样才能让

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

~/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命令

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

找到-名称“test.txt”>result.txt

您的“for t in~/test/sample*/test/txt;do echo$t>>result.txt;done”中的微小更改

“对于t in~/test/sample*/test.txt;do echo$t>>result.txt;done”

这应该对你有用


谢谢

这很简单,简单,也很棒!谢谢我打错了命令。我真的打了你写的东西。谢谢