文本查看:
1、cat:连接文件并显示 --tac:反向查看文件
-n 显示行号
-E 显示行结束符($)
2、more,less分屏显示
more:向后翻
less :和man一样
3、head,tail
head:查看前n(10)行
tail:查看后n行
tail -f:查看文件尾部,不退出,等待显示后续追加至此文件的新内容
文本处理:
1、cut:剪切
-d:指定字段分隔符
-f:指定文件
-f1
-f1,3
-f1-3
例子:
[root@m01 /]# cut -d : -f1,3 /etc/passwd
root:0
bin:1
daemon:2
adm:3
lp:4
sync:5
shutdown:6
halt:7
mail:8
operator:11
games:12
ftp:14
nobody:99
systemd-network:192
dbus:81
polkitd:999
postfix:89
sshd:74
nginx:998
2、sort:文本排序(默认按照acsii码)
-n:按数值大小排序
-r:降序排序
-t:指定分隔符
-k:指定第几个字段
例子:[root@m01 ~]# sort -t: -k3 -n /etc/passwd
3、uniq:报告或忽略重复的行
用法:uniq 【option】【filename】
-d 显示重复的行
-c 显示某一行重复的次数
4、wc:(world count),tr:逐个字符替换或删除
例子: tr -d '3' < ~/sort.txt --删除文件中含有‘3’的字符