怎样在Linux下搜索包含特定字串的文件

发现这个功能非常有用,必须收藏起来。

grep -rnw ‘/path/to/somewhere/’ -e ‘pattern’

  • -r or -R is recursive,
  • -n is line number, and
  • -w stands for match the whole word.
  • -l (lower-case L) can be added to just give the file name of matching files.
  • -e is the pattern used during the search

或者

grep -Ril “text-to-find-here” /

  • i stands for ignore case (optional in your case).
  • R stands for recursive.
  • l stands for “show the file name, not the result itself”.
  • / stands for starting at the root of your machine.

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Time limit is exhausted. Please reload CAPTCHA.