[10:44:34 root@aiyoubucuo ~]$cat ybw 123456 yang [10:44:44 root@aiyoubucuo ~]$tac ybw yang 123456
[10:44:34 root@aiyoubucuo ~]$cat ybw 123456 yang
[10:45:24 root@aiyoubucuo ~]$rev ybw 654321 gnay
[10:54:19 root@aiyoubucuo ~]$hexdump -C /etc/issue 00000000 5c 64 20 5c 6d 20 5c 6e 20 5c 73 20 0a |d m s .| 0000000d
[11:12:52 root@aiyoubucuo ~]$cat /dev/urandom |tr -dc '[:alnum:]'|head -c 12 1epM2tyuKq4F
[11:21:57 root@aiyoubucuo ~]$cat ybw|tail -n +3 3 4 5 6

[11:44:21 root@aiyoubucuo ~]$cat /etc/passwd|cut -d: -f1 root bin daemon adm lp sync shutdow
以冒号为分隔符,取第一列字段
[11:49:35 root@aiyoubucuo ~]$paste ybw yang 1 a 2 b 3 c 4 d 5 e 6 f [11:49:47 root@aiyoubucuo ~]$paste -d: ybw yang 1:a 2:b 3:c 4:d 5:e 6:f [11:50:23 root@aiyoubucuo ~]$paste -s ybw yang 1 2 3 4 5 6 a b c d e f
[11:51:06 root@aiyoubucuo ~]$cat /etc/passwd|wc -l 50 文件行数50行
[16:07:58 root@centos7 ~]$df |tr -s ' ' '%'|cut -d% -f 5|tail -n +2|sort -rn
14
3
3
1
0
0
0
0
看出磁盘最高使用率
[16:08:56 root@centos7 ~]$df |tr -s ' ' '%'|cut -d% -f 5|tail -n +2|sort -rn|uniq -c
1 14
2 3
1 1
4 0
sort配合uniq使用
[14:54:40 root@aiyoubucuo ~]$diff -u ybw yang --- ybw 2020-12-10 14:54:18.657174910 +0800 +++ yang 2020-12-10 14:53:19.613027594 +0800 @@ -1,5 +1,5 @@ nihao -wang +ybw lili -zhang +xiaoming
[16:42:27 root@aiyoubucuo ~]$ifconfig | egrep -o '(([0-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])' 10.0.0.8 255.255.255.0 10.0.0.255 127.0.0.1 255.0.0.0 192.168.122.1 255.255.255.0 192.168.122.255
取出ip地址
[16:47:16 root@centos7 ~]$grep -nr 'PS' /etc/profile.d/
/etc/profile.d/bash_completion.sh:2:[ -z "$BASH_VERSION" -o -z "$PS1" -o -n "$BASH_COMPLETION_COMPAT_DIR" ] && return
/etc/profile.d/colorls.sh:2:PS1="[e[1;36m][[e[0m] [e[1;32m]u[e[31m]@h[e[1;37m] W[e[1;35m]][e[0m]$"
可以根据字符查找在哪个文件里
17.文本三剑客之sed
sed [选项] ... 'script;script;...' 输入文件..
-n 不输出模式空间内容到屏幕,即不自动打印
-e 多点编辑
-f file 从指定文件中读取编辑脚本
-r, -E 使用扩展正则表达式
-i.bak 备份文件并原处编辑
命令
p 打印当前模式空间内容,追加到默认输出之后
d 删除模式口空间匹配的行,并立即启用下一轮循环
a[]text 在指定行后面追加文本 ,支持
i[]text 在行前面插入文本
c[]text 替换行为单行或多行文本
s/pattern/string/修饰符 查找替换,支持使用其它分隔符,可以是其它形式:s@@@,s###替换修饰符
g 行内全局替换
p 显示替换成功的行
1.[16:36:02 root@centos7 ~]$sed -n '2p' /etc/passwd bin:x:1:1:bin:/bin:/sbin/nologin
输出文件第二行
2.[16:43:12 root@centos7 ~]$df |sed -n '/^/dev/sd/p'
/dev/sda1 1038336 145256 893080 14% /boot
取/dev/sd开头的行打印
3.[16:48:30 root@centos7 ~]$seq 10 |sed -n '2,3p'
2
3
取2至3行打印
[16:53:04 root@centos7 ~]$seq 10 |sed -n '2~2p'
2
4
6
8
10
取偶数行打印
[19:58:40 root@centos7 ~]#cat ybw
aaaaaaaaa
cccccccccccc
zzzzzzzzzzz
[20:02:03 root@centos7 ~]#sed -i '/a/as' ybw
[20:09:24 root@centos7 ~]#cat ybw
aaaaaaaaa
s
cccccccccccc
zzzzzzzzzzz
-i保存文件,a在指定行文本后追加文本,支持 实现多行追加
i行前,c代替行
sed -i '/^$/d' file
删除文件空行
[17:26:13 root@aiyoubucuo ~]#sed -nr 's/(r..t)/1er/p' /etc/passwd
rooter:x:0:0:root:/root:/bin/bash
替换,1代表括号内容r..t替换为r..ter
[19:29:44 root@aiyoubucuo ~]#echo a.b.c.gz |sed -nr 's/.*.([^.]+)$/1/p'
gz
取文件的前缀和后缀,前面是任意字符,结尾的意思是排除点一个或多个字符,前面.用转义符转译代表.gz括号取出结尾
[16:39:19 root@centos7 ~]$df |sed -nr '/dev/sda/s/.* ([0-9]+)%.*/1/p'
14
取以/dev/sda开头行的分区利用率