How can I grep hidden files?

前端 未结 10 1214
北荒
北荒 2020-12-07 14:27

I am searching through a Git repository and would like to include the .git folder.

grep does not include this folder if I run



        
相关标签:
10条回答
  • 2020-12-07 15:02

    To find only within a certain folder you can use:

    ls -al | grep " \."
    

    It is a very simple command to list and pipe to grep.

    0 讨论(0)
  • 2020-12-07 15:05

    To search within ONLY all hidden files and directories from your current location:

    find . -name ".*" -exec grep -rs search {} \;
    

    ONLY all hidden files:

    find . -name ".*" -type f -exec grep -s search {} \;
    

    ONLY all hidden directories:

    find . -name ".*" -type d -exec grep -rs search {} \;
    
    0 讨论(0)
  • 2020-12-07 15:07

    To prevent matching . and .. which are not hidden files, you can use grep with ls -A like in this example:

    ls -A | grep "^\."
    

    ^\. states that the first character must be .

    The -A or --almost-all option excludes the results . and .. so that only hidden files and directories are matched.

    0 讨论(0)
  • 2020-12-07 15:15

    All the other answers are better. This one might be easy to remember:

    find . -type f | xargs grep search
    

    It finds only files (including hidden) and greps each file.

    0 讨论(0)
提交回复
热议问题