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

问题描述:

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

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

使用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 
+1

或者只是'找到-ls'。 – tripleee 2014-10-29 18:34:54

+0

@tripleee我觉得很愚蠢,我甚至都不知道'find -ls'。谢谢。 – ptierno 2014-10-29 18:38:52