1.grep命令
从文件中通过关键字过滤文件行
语法: grep [-n] 关键字 文件路径
·选项n,可选,表示在结果中显示匹配的行号
·参数,关键字,必填,表示过滤的关键字,带有空格或其它特殊符号,建议使用""将关键字包围起来
·参数,文件路径,必填,表示要过滤内容的文件路径,可作为内容输入端口
wendy@wendydeMacBook-Air ~ % touch test.txt wendy@wendydeMacBook-Air ~ % cat test.txt
Wendy is a great woman.
The great code is 003456.% wendy@wendydeMacBook-Air ~ % grep -n "great" test.txt
1:Wendy is a great woman.
2:The great code is 003456.
2.wc命令做数量统计
统计文件的行数、单词数量等
语法: wc [-c -m -w] 文件路径
·选项 -c 统计bytes数量
·选项 -m 统计字符数量
·选项 -l 统计行数
·选项 -w 统计单词数量
·参数 文件路径,被统计的文件,可作为内容输入端口
wendy@wendydeMacBook-Air ~ % wc test.txt
1 10 49 test.txt
wendy@wendydeMacBook-Air ~ % wc -c test.txt
49 test.txt
wendy@wendydeMacBook-Air ~ % wc -m test.txt
49 test.txt
wendy@wendydeMacBook-Air ~ % wc -l test.txt
1 test.txt
wendy@wendydeMacBook-Air ~ % wc -w test.txt
10 test.txt
3.管道符(|)
|:将管道符左边命令的结果,作为右边命令的输入
wendy@wendydeMacBook-Air ~ % cat test.txt | grep great test.txt
Wendy is a great woman.
The great code is 003456.
完结 🎉 继续更新 加个关注收藏一下叭~