find $HOME -name "hello.c" -print
这个命令将在整个$HOME
(即/home/username/
)系统中搜索所有名为“hello.c”的文件,并显示它们的路径:
/Users/user/Downloads/hello.c
/Users/user/hello.c
然而,它将不会匹配 HELLO.C
或者 HellO.C
。如果要进行大小写不敏感的匹配,请使用 -iname
选项,如下所示:
find $HOME -iname "hello.c" -print
样例输出:
/Users/user/Downloads/hello.c
/Users/user/Downloads/Y/Hello.C
/Users/user/Downloads/Z/HELLO.c
/Users/user/hello.c
将-type f
选项传递以仅搜索文件:
find /dir/to/search -type f -iname "fooBar.conf.sample" -print
find $HOME -type f -iname "fooBar.conf.sample" -print
-iname
在GNU或BSD(包括OS X)版本的find命令上都可以使用。如果您的find命令版本不支持-iname
,请尝试使用以下语法与grep
命令:
find $HOME | grep -i "hello.c"
find $HOME -name "*" -print | grep -i "hello.c"
或者尝试
find $HOME -name '[hH][eE][lL][lL][oO].[cC]' -print
样例输出:
/Users/user/Downloads/Z/HELLO.C
/Users/user/Downloads/Z/HEllO.c
/Users/user/Downloads/hello.c
/Users/user/hello.c