文章目录
查看和处理文件内容
1、文本文件和二进制文件
文本文件
-
ASCII、UTF-8、Unicode、ANSI
-
txt、xml、conf、properties、yml等配置文件、日志文
件、源代码
二进制文件
可执行程序、图片、音频、视频
2、常用命令
cat
全拼:concatenate [kənˈkætəneɪt] 连接
格式:cat 文件名
more/less
more/less分屏操作
more/less搜索
/[查找字符] # 配合n键,从上往下查所有。
?[查找字符] # 配合n键,从下往上查所有。
按 Enter 键后:
n键盘查找下一个符合的内容。
N上一个符合的内容。
head/tail
head -n 10 redis.conf
tail -n 10 info.log
tail -f /var/log/messages
grep
全拼:Globally search a Regular Expression and
Print
全局搜索正则表达式并打印
格式:grep 选项 模式 文件名
管道符号pipe
把前一个命令原本要输出到屏幕的数据当作是后一个命
令的标准输入
command1 | command2 | command3
cat test.log | more -5 每次显示5行
ps -ef | less -N 显示行号
netstat -an|grep 3306
cat -n info.log |grep "debug" | more
wc
全拼:word count -l或--lines 显示行数
-w或--words 只显示字数
wc -l redis.conf
wc -w redis.conf
diff
全拼:different
diff diff_A.txt diff_B.txt
diff -r aaa bbb