Files
2026-06-30 22:02:28 +08:00

41 lines
992 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# grep \[-n -i -v -r] \[关键字] \[内容输入]
作用:从文件中通过关键字过滤文件行
参数:
- -n:可选 表示在结果中显示匹配的行号
- -i:可选 忽略大小写
- -v 反向过滤,输出不包含关键字
- -r:递归搜索目录
- 关键字:必填 表示过滤的关键字,带有空格或其他特殊符号用`""包裹起来
- 内容输入:必填 表示要过滤内容的文件路径
示例:
- grep -n "kister" ~/test.txt
- grep "kister" ~/test.txt
- cat log.txt | grep -i "error" | wc -l
# wc \[-c -m -l -w] \[内容输入]
作用:统计文件的行数、单词量等
参数:
- -c:统计bytes数量
- -m:统计字符数量
- -l:统计行数
- -w:统计单词数量
- 内容输入:必填 表示要统计内容的文件路径
示例:
- wc test.txt
- wc -lw test.txt
# 管道符
符号:`|
作用:将左边命令的结果作为右边命令的输入
示例:
- cat text.txt | grep "kister"
- ls -la / | grep "home"