【问题标题】:Which command do I use to find specific file starting from specific directory?我使用哪个命令从特定目录开始查找特定文件?
【发布时间】:2014-12-25 14:30:51
【问题描述】:

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

我需要先'su username',然后是 ls->cd 还是有特定的命令这样做?

【问题讨论】:

    标签: linux shell unix command-line command


    【解决方案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
    

    【讨论】:

    • @tripleee 我什至不知道find -ls 感到很愚蠢。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 2019-12-03
    • 1970-01-01
    • 2020-10-19
    • 1970-01-01
    • 2012-02-11
    • 2021-09-11
    • 2022-01-06
    相关资源
    最近更新 更多