Linux grep 或 find 用法

4 linux grep

如何在硬盘上找到以 开头的文件io_file

我试过:

grep -r io_file*` 
Run Code Online (Sandbox Code Playgroud)

find -name io_file*
Run Code Online (Sandbox Code Playgroud)

find没有返回任何东西,而grep似乎需要很长时间没有任何结果。

我究竟做错了什么?

Joh*_*kin 11

find / -name 'io_file*'

第一个参数将指定搜索应该从哪里开始。/意味着您的整个硬盘驱动器。要仅搜索当前目录(和子目录),请使用:find .

如果搜索字符串包含 shell 元字符(例如星号),则必须用引号引起来。否则,它将被 shell 解析而永远不会被find.


Tom*_*Tom 7

find / -name 'io_file*' -type f 2>/dev/null



   /: Start looking from root directory

   -type f: Only search for regular files

    2>/dev/null: Redirect errors to /dev/null. (handy if you are not root and
                 not interested in all the "access denied" messages)
Run Code Online (Sandbox Code Playgroud)

请记住 grep 和 find 做不同的事情。

grep 搜索命名的输入文件(或标准输入,如果没有文件被命名,或文件名 - 已给)包含匹配给定 PATTERN 的行。默认情况下,grep 打印匹配的行。

find - 在目录层次结构中搜索文件