Mac终端搜索命令行工具

mdfind命令就是Spotlight功能的终端界面

1
2
mdfind -name "Photo 1.PNG"  //搜索文件名Photo 1.PNG
mdfind -onlyin ~/Library plist //搜索指定文件夹

The Silver Searcher

https://github.com/ggreer/the_silver_searcher

1
brew install the_silver_searcher //安装

使用

1
2
Usage: ag [FILE-TYPE] [OPTIONS] PATTERN [PATH]
ag [文件类型] [选择] [正则] []

常用命令行

1
2
3
4
5
6
常用参数
-i 忽略大小写
-l 只列出文件名
-g 文件名匹配
--php 只搜索php文件
--ignore-dir 忽略目录
1
2
3
4
5
ag  动画   			//搜索当前路径带文件名或文件内容带“动画”文件
ag -g 动画 //搜索当前路径文件名带“动画”文件
ag "动画" './' //搜索该目录下以及其子目录下的所有含有"image"的文件
ag --markdown 动画 //搜索指定类型
ag --ignore-dir sitedata --php hx /www/baidu.com

-c –count Only print the number of matches in each file.

匹配文件关键词个数

-g PATTERN Print filenames matching PATTERN

匹配文件

-l –files-with-matches Only print filenames that contain matches

只输出匹配内容//取相反结果 用大写-L

-o –only-matching Prints only the matching part of the lines

输出匹配所在行

文章作者: kyren
文章链接: http://huluo666.github.io/2017/12/29/Mac终端搜索命令行工具/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Kyren's Blog