[英]search all files in a directory and get their full path using bash script
我有这样的目录结构.ABC / 123,ABC / 456,ABC / 789,在每个编号的目录中我都有很多文件。我想要的是能够搜索编号中找到的所有名为XYZ.txt的文件ABC目录中的目录,并使用脚本获取它们在变量或数组上的完整路径。
You can try: 你可以试试:
cd "ABC"
array=($(find "$PWD" -type f -name "XYZ.txt"))
Leave away the cd ABC, otherwise "ABC/" will not be part of the output. 放弃cd ABC,否则“ ABC /”将不属于输出。 find searches the curent directory, which makes specifying $PWD dispensable.
find查找当前目录,这使得指定$ PWD不再需要。 Also the constraint to files by -type is not necessary if you define the name with .txt extension, supposed there aren't any directories called like this.
同样,如果您以.txt扩展名定义名称,则不必按-type约束文件,前提是没有这样的目录。
array=($(find -name "*.txt"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.