字符处理命令

sort  排序

[root@web01 ~]# sort a.txt
3:5
a:4
b:33333333
c:2
d:2222
e:223
f:111
[root@web01 ~]# sort -t ":" -k2 a.txt
f:111
c:2
d:2222
e:223
b:33333333
a:4
3:5
[root@web01 ~]# sort -t ":" -k2 -n a.txt
c:2
a:4
3:5
f:111
e:223
d:2222
b:33333333
[root@web01 ~]# sort -t ":" -k2 -n -r a.txt
b:33333333
d:2222
e:223
f:111
3:5
a:4
c:2

uniq  去重复                                

 [root@web01 ~]# sort c.txt 

111
111
111
222
222
333
4444444444444
4444444444444
555555555555
666666666
[root@web01 ~]# sort c.txt |uniq
111
222
333
4444444444444
555555555555
666666666
[root@web01 ~]# sort c.txt |uniq -c # # 显示重复的行的个数
3 111
2 222
1 333
2 4444444444444
1 555555555555
1 666666666
[root@web01 ~]# sort c.txt |uniq -d # 只显示重复的行
111
222
4444444444444
[root@web01 ~]# sort c.txt |uniq -u # 只显示不重复的行
333
555555555555
666666666

cut 类似 awk

[root@web01 ~]# head -5 /etc/passwd

root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

[root@web01 ~]# head -5 /etc/passwd | cut -d: -f1
root
bin
daemon
adm
lp
[root@web01 ~]# head -5 /etc/passwd | cut -d: -f1-3
root:x:0
bin:x:1
daemon:x:2
adm:x:3
lp:x:4
[root@web01 ~]# head -5 /etc/passwd | cut -d: -f1,3
root:0
bin:1
daemon:2
adm:3
lp:4
[root@web01 ~]# head -5 /etc/passwd | cut -d: -f1,3,5,7
root:0:root:/bin/bash
bin:1:bin:/sbin/nologin
daemon:2:daemon:/sbin/nologin
adm:3:adm:/sbin/nologin
lp:4:lp:/sbin/nologin

wc 统计命令

[root@web01 ~]# wc -c /etc/passwd
2413 /etc/passwd
[root@web01 ~]# ll /etc/passwd
-rw-r--r-- 1 root root 2413 10月 26 10:16 /etc/passwd
[root@web01 ~]#
[root@web01 ~]#
[root@web01 ~]#
[root@web01 ~]# wc -l /etc/passwd
46 /etc/passwd
[root@web01 ~]# cat /etc/passwd | wc -l
46
[root@web01 ~]#
[root@web01 ~]# ps aux | wc -l
118
[root@web01 ~]#
[root@web01 ~]# vim e.txt
[root@web01 ~]# cat e.txt
abc_123 bcd_1_2 aaabbb 11111
[root@web01 ~]# wc -w e.txt
4 e.txt
[root@web01 ~]# vim e.txt
[root@web01 ~]# cat e.txt
abc_123 bcd_1_2 aaabbb 11111
22222 ccc
[root@web01 ~]# wc -w e.txt
6 e.txt

二:打包压缩
打包——》把多个东西扔到袋子里
压缩-》把袋子的空间挤压一下

方式一:gzip与bzip2
打包压缩
tar cvzf bak.tar.gz a.txt b.txt c.txt # gzip压缩算法
tar cvjf bak.tar.bz2 a.txt b.txt c.txt # bzip2压缩算符


解包
tar xvf bak4.tar.bz2 -C 目标文件夹


# 了解
bunzip2 bak4.tar.bz2
gunzip bak4.tar.gz


方式二:
zip bak.zip /root/a.txt /etc/hostname /etc/passwd
unzip bak.zip
unzip bak.zip -d /aaa



tar cvzf `date "+%Y_%m_%d_%H_%M_%S"`_etc_bak.tar.gz /etc/

三、文件系统
操作系统
文件系统(属于操作系统的一部分)----》提供了文件的概念
硬盘


文件系统是操作系统中负责操作硬盘的一段程序,文件系统提供了文件的概念



dba->稳

原文地址:https://www.cnblogs.com/dachangtui/p/13888005.html