从特定目录开始,我使用哪个命令查找特定文件?

时间:2014-10-29 18:22:53

标签: linux shell unix command-line command

哪个命令允许从主目录开始查找特定文件(例如:test.doc)?

我首先需要'su username',然后是ls-> cd或者是否有特定的命令执行此操作?

1 个答案:

答案 0 :(得分:1)

使用find命令:

 find /home/foo -name 'test.doc'

或者对不区分大小写的搜索:

 find /home/foo -iname 'test.doc'

这将输出包含相对路径的文件名。如果您想要一些更详细的信息,例如ls -l test.doc的输出,您可以这样做:

 find /home/foo -iname 'test.doc' -exec ls -lh {} \;

或者只是将其传递给xargs

 find /home/foo -iname 'test.doc' | xargs ls -lh