如何使用shell查找某个文件的完整路径?
问题描述:
我得到一个问题,在我的Ubuntu中,我在/local/jenkins/scripts
这样的目录下工作,这里有很多子目录,我想要获取目录中的所有excute.sh文件,但是如果我使用“find -name excute.sh
”,它会返回相关路径的列表,如下所示。如何使用shell查找某个文件的完整路径?
./TEST933/excute.sh
./TEST923/excute.sh
./TEST323/excute.sh
./TEST920/excute.sh
请问您可以请分享如何获取完整路径列表,如下所示?谢谢!
/local/jenkins/scripts/TEST933/excute.sh
/local/jenkins/scripts/TEST923/excute.sh
/local/jenkins/scripts/TEST323/excute.sh
/local/jenkins/scripts/TEST920/excute.sh
答
with readlink;
find -name excute.sh -exec readlink -f {} \;
答
你可以使用这个;
find /local/jenkins/scripts/ -name excute.sh
例如;
$ find -name excute.sh
./TEST920/excute.sh
./TEST933/excute.sh
./TEST923/excute.sh
./TEST323/excute.sh
$ find /tmp/test/ -name excute.sh
/tmp/test/TEST920/excute.sh
/tmp/test/TEST933/excute.sh
/tmp/test/TEST923/excute.sh
/tmp/test/TEST323/excute.sh
可能重复[如何列出文件与他们的绝对路径在Linux?](http://stackoverflow.com/questions/246215/how-can-i-list-files-with-their-绝对路径在Linux的) –