文本处理工具:cut,sort,uniq,tr,diff,paste,patch

正则表达式:标准和拓展,grep

脚本编程基础:[],[[]],if,case,三个引号区别,位置变量,圆括号与花括号区别,.vimrc文件

文件查找与压缩:find,locate,tar,unzip,gzip等,split

文本处理工具

1、cut

  • -d指定分隔符。比如-d: -d' '
  • -f指定取第几列。比如-f1,3
  • --output-delimiter指定显示的分隔符

tr -s压缩 -d删除 -c除了

2、使用tr和cut取磁盘的百分比

[root@glowing-bliss-1 data]# df -h | tr -s ' ' | cut -d' ' -f5 | tr -dc '[0-9]\n'

0
0
5
0
32
67
32
0

3、取IP

[root@glowing-bliss-1 data]# ifconfig lo | head -2 | tail -1 | tr -s ' ' | cut -d' ' -f3
127.0.0.1
[root@glowing-bliss-1 data]# ifconfig lo | head -2 | tail -1 | tr -s ' ' : | cut -d: -f3
127.0.0.1

4、paste合并文件

合并两个文件.-d指定分割符

下面为合并a.txt和1.txt,分隔符为:

qqq@qqq:~$ cat a.txt 
a
b
c
d
qqq@qqq:~$ cat 1.txt 
1
2
3
4
qqq@qqq:~$ paste 1.txt a.txt -d:
1:a
2:b
3:c
4:d

5、wc命令

统计行,单词,字节数

-m字符数 -L文件最宽的一行

[root@k8s-master ~]# wc /etc/passwd
 20  28 874 /etc/passwd
[root@k8s-master ~]# wc -l /etc/passwd
20 /etc/passwd
[root@k8s-master ~]# wc -c /etc/passwd
874 /etc/passwd
[root@k8s-master ~]# wc -w /etc/passwd
28 /etc/passwd
[root@k8s-master ~]# wc -lwc /etc/passwd
 20  28 874 /etc/passwd
[root@k8s-master ~]# wc -clw /etc/passwd
 20  28 874 /etc/passwd

6、wc显示当前目录下文件名最长的文件的长度

[root@k8s-master ~]# ls -1 /etc/ | wc -L
24

7、sort命令

默认是字母排序

-u删除输出中的重复行;

-t c使用c作为字段界定符(就是分割符,和cut的-d一样);

-k x 使用第x列作为基准进行排序

7.1 基于UID对passwd文件进行排序

[root@k8s-master ~]# cat /etc/passwd | sort -t: -k3 -nr
qqq:x:1000:1000:qqq:/home/qqq:/bin/bash
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
...

7.2 df磁盘利用率排序

[root@glowing-bliss-1 data]# df -h | tr -s ' ' | cut -d' ' -f5 | tr -dc '[0-9]\n' | sort -n

0
0
0
0
5
32
32
67

8、uniq

从输出中删除前后相接的重复行

-d仅显示重复果的行

-u仅显示不曾重复的行

8.1【面试题】统计两个不同目录中相同的文件列表

qqq@qqq:~$ ls . /tmp -1 | sort | uniq -d
10.txt
1.txt
2.txt
3.txt
4.txt
5.txt
6.txt
7.txt
8.txt
9.txt
qqq@qqq:~$ (ls /tmp -1;ls . -1) | sort | uniq -d  #这样显示不显示目录
10.txt
1.txt
2.txt
3.txt
4.txt
5.txt
6.txt
7.txt
8.txt
9.txt

8.2【面试题】统计 两个不同目录中不同的文件列表

qqq@qqq:~$ (ls /tmp -1;ls . -1) | sort | uniq -u #这样显示不显示目录
{1..txt}
a.txt
gems
myblogs
systemd-private-b8854b73c0e2479db1d56e43d8995bec-systemd-resolved.service-AcZjbU
systemd-private-b8854b73c0e2479db1d56e43d8995bec-systemd-timesyncd.service-sngpw9
vmware-root_643-3979708515

9、lastb显示btmb文件内容

[root@glowing-bliss-1 data]# lastb -f /var/log/btmp

10、【面试题】写一个脚本进行nginx日志统计,统计访问IP最多的前十

[root@glowing-bliss-1 data]# awk '{print $1}' /var/log/nginx/access.log | sort -nr | uniq -c | sort -nr | head

11、diff比较两个文件的不同

-u显示 统一的diff格式文件

qqq@qqq:~$ diff 1.txt  2.txt -u
--- 1.txt   2019-08-04 10:07:47.384154832 +0000
+++ 2.txt   2019-08-04 10:08:01.620224554 +0000
@@ -1,3 +1,4 @@
 1
 2
 3
+4

13、patch

复制在其他文件中的改变了的文件(慎用)

-b选项来自动备份改变了的文件


正则表达式(标准和拓展)

一、基本语法

标准正则表达式中需要转义的字符有:(,),{,},|,+,.,

拓展正则表达式下词首,词尾,分组的引用这些的反斜杠不能省

  • *表示匹配任意次,包括0次
  • .*表示任意长度的任意字符
  • ?表示匹配前面字符0次或一次
  • +表示匹配前面字符一次或多次
  • {n,m}表示匹配前面字符n到m次
  • ^表示行首
  • $表示行尾
  • ^$表示空行^[[:space:]]*$表示空白行
  • \<词首 \>行尾
  • \ hello单词(单词的组成:字母数字下划线,其他字符均为分隔符)
  • (.*)括号为分组,\1 \2为使用前面括号的内容

2、显示磁盘分区使用率

[root@glowing-bliss-1 data]# df -h | grep '^/dev/sd' | tr -s ' ' | cut -d' ' -f5 | cut -d% -f1 | sort -n
32
67

3、将root替换成rooter

:%s@\(root\)@\1er@g

4、正则表达式获取IP

qqq@qqq:~$ ifconfig ens33 | grep -Eo '([0-9]{,3}\.){3}([0-9]{,3})'
192.168.38.148
255.255.255.0
192.168.38.255

5、找出ntestat -atn输出中LISTEN后跟任意空白字符的行

qqq@qqq:~$ netstat -atn | grep -E 'LISTEN[[:space:]]*$'
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN 

6、查看每个IP建立的连接数

qqq@qqq:~$ cat ss.log  | grep ESTAB | tr -s ' ' : | cut -d: -f6 | sort  | uniq -c | sort -nr | head -3
     44 127.0.0.1
     10 113.234.28.244
      8 124.64.18.135

7、取CentOS7的版本号

[root@glowing-bliss-1 data]# cat /etc/centos-release | grep -Eo '[0-9]+' | head -1
7

8、grep

-A # 后多少行
-B # 前多少行
- # 前后各多少行
-i 忽略大小写
-e 相当于逻辑中的or,可以多次使用
-w 匹配整个单词

9、misc目录

光盘会自动挂载到/misc/cd目录
autofs的作用,没有的话装一个并启动

10、nmap扫描局域网的机器

查看当前局域网哪些IP被使用了

[root@centos7 ~]# nmap -v -sn 192.168.10.1/24 | grep -B1 "Host is up" | grep report | cut -d' ' -f5
192.168.10.1
192.168.10.6
192.168.10.12
192.168.10.14
192.168.10.16
192.168.10.19
192.168.10.20
192.168.10.28
...

11、基本正则表达式元字符

字符匹配

  • . 匹配任意单个字符
  • [] 匹配指定范围内的任意单个字符。[.?]表示匹配.或者\或者问号
  • [^] 匹配范围之外的任意单个字符
  • [:digit:]等等一系列

12、cat -A

可以查看某些看不到的东西:Tab、回车换行等

[root@centos7 ~]# cat -A 1.txt 
a b^Ic$
dd$
$
d$
$
$

13、程序执行方式

高级语言->编译器->机器代码->执行

14、.vimrc vim配置文件

root@qqq:~# vim ~/.vimrc 
root@qqq:~# cat ~/.vimrc 
set ignorecase
set cursorline
set autoindent
set ai
autocmd BufNewFile *.yaml exec ":call SetTitle()"

func SetTitle()
        if expand("%:e") == 'yaml'
        call setline(1,"#**************************************************************")
        call setline(2,"#Author:                     uscwifi")
        call setline(3,"#QQ:                         2*******1")
        call setline(4,"#Date:                       ".strftime("%Y-%m-%d"))
        call setline(5,"#FileName:                   ".expand("%"))
        call setline(6,"#URL:                        http://www.baidu.com")
        call setline(7,"#Description:                The test script")                                                 
        call setline(8,"#Copyright (C):              ".strftime("%Y")." Copyright ©  站点名称  版权所有")
        call setline(9,"#************************************************************")
        call setline(10,"")
        endif
endfunc
autocmd BufNewFile * normal G

15、将脚本的目录路径放入PATH路径,直接执行脚本

执行脚本的方式

  • 1、bash date.sh
  • 2、相对路径法 ./date.sh
  • 3、绝对路径法
  • 4、PATH变量法,scripts的目录加入PATH变量(写入bashrc或profile,然后source)
  • 5、cat date.sh|bash

16、脚本的两种错误

shell与python都属于解释型语法,边解释边执行;C语言,JAVA等是编译型语言,全部代码编译后才能执行

  • 1、语法错误,最好使用bash -n date.sh检查以减少语法错误,语法错误后的命令都不会执行,但前面的命令都会执行
  • 2、其他错误:比如命令不存在,命令错误等。不影响后续代码的执行。在脚本开始加上set -e可以让脚本出现错误时立即停止执行。
  • bash -n检查语法错误,写完脚本务必检查。
  • bash -x用于调试脚本,查看脚本的执行过程,执行逻辑。

17、shell计算求和,实现算数运算的几种方法:

17.1、let命令,比较常用

[root@centos7 ~]# x=10
[root@centos7 ~]# y=17
[root@centos7 ~]# let z=$x+$y
[root@centos7 ~]# echo $z
27

17.2、$(())比较常用

[root@centos7 ~]# x=100
[root@centos7 ~]# y=302
[root@centos7 ~]# z=$(($x+$y))
[root@centos7 ~]# echo $z
402

17.3、bc求和,较为常用

[root@centos7 ~]# x=123
[root@centos7 ~]# y=986
[root@centos7 ~]# echo $x+$y | bc
1109

17.4 $[]

[root@qqq ~]# x=10
[root@qqq ~]# y=20
[root@qqq ~]# z=$[$x+$y]
[root@qqq ~]# echo $z
30

18、shell脚本的颜色

echo必须要-e参数才可以使用颜色

[root@glowing-bliss-1 ~]# cat /data/docker_stats.sh 
#!/bin/bash

RED="\e[31;1m"
GREEN="\e[32;1m"
YELLOW="\e[33;1m"
END_COLOR="\e[0m"
# 用法
echo -e "\n${YELLOW}################################${END_COLOR}\n"

19、cat /proc/partitions

20、单引号,双引号,反引号

  • 单引号:强引用,不识别命令,不识别变量
  • 双引号:不识别命令,但是别变量;
  • 反向单引号,都识别
[root@glowing-bliss-1 ~]# echo '$HOSTNAME'
$HOSTNAME
[root@glowing-bliss-1 ~]# echo "$HOSTNAME"
glowing-bliss-1.localdomain
[root@glowing-bliss-1 ~]# ls `pwd`
virt-sysprep-firstboot.log
[root@glowing-bliss-1 ~]# echo `hostname`
-bash: echglowing-bliss-1.localdomain: command not found

21、程序有父进程和子进程

21.1、查看进程之间的父子关系

pstree

21.2、查看当前进程ID

echo $BASHPID

echo $$ echo $$经常在脚本中使用,查看脚本运行时的进程ID

21.3、查看父进程ID

echo $PPID

22、set

unset删除变量

set查看

set -C执行后无法覆盖已经存在的文件

23、生成随机数和随机颜色

[root@qqq ~]# echo $RANDOM
30700
[root@qqq ~]# echo ${RANDOM}
24744
[root@qqq ~]# echo $[${RANDOM}%7+31]
33
[root@qqq ~]# echo $[${RANDOM}%7+31]
32

shell脚本编程基础

[.?]表示. ? 中的某一个

grep -E "(bash|nologin)$" /etc/passwd grep -E "bash$|nologin$" /etc/passwd

1、环境变量的声明

  • export EDITOR=vim 定义默认编辑器,要写入profile
  • declare -x EDITOR=vim 与上面等价
  • declare -r声明为只读变量 等于 readonly name

2、set --

清空所有位置变量

3、变量引用要习惯加上花括号

  • ${10} ${DATE} ${PWD}

4、位置变量

5、()与{}的区别

()会开启子进程
{}不会开启子进程
[root@qqq ~]# echo $BASHPID
43519
[root@qqq ~]# (echo $BASHPID)
44162
[root@qqq ~]# { echo $BASHPID; }
43519

6、if,中括号,正则表达式

# 必须使用双中括号和波浪符
[root@qqq ~]# file=123.sh
[root@qqq ~]# [[ "${file}" =~ ^.*\.sh$ ]] && echo "This is a shell script." || echo "NoNoNo."
This is a shell script.
[root@qqq ~]# file=123.txt
[root@qqq ~]# [[ "${file}" =~ ^.*\.sh$ ]] && echo "This is a shell script." || echo "NoNoNo."
NoNoNo.
# [[]]特点:
# == != 符号右侧可以使用通配符,左侧变量建议加""  右侧不加
# =~ 右侧可以使用正则表达式,左侧变量名建议加""   右侧不加

7、禁止普通用户登陆快捷方法

touch /etc/nologin

8、过滤符号要求的IP

[root@qqq ~]# ifconfig eth0 | grep -Eo "([0-9]+\.){3}([0-9]+)" | head -1
172.18.144.235
[root@qqq ~]# ifconfig eth0  | grep -Eo '(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])' | head -1
172.18.144.235
[root@qqq ~]# IP=1.2.3.4
[root@qqq ~]# [[ "$IP" =~ ^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ ]] && echo This IP is legal. || echo This IP is not legal.
This IP is legal.

9、环境变量加载的顺序

# 交互式登陆
    (1)直接通过终端输入账号密码登陆
    (2)使用su - UserName切换用户
    执行顺序:/etc/profile -> /etc/profile.d/*.sh -> ~/.bash_profile -> ~/.bashrc - > /etc/bashrc
# 非交互式登陆
    (1)su UserName
    (2)图形化界面打开的终端
    (3)执行脚本
    (4)任何其他的bash实例
    执行顺序:/etc/profile.d/*.sh -> /etc/bashrc -> ~/.bashrc

10、bash,.,source区别

bash命令会开启子进程
bash执行脚本,绝对路径执行脚本会开启子进程
.或者source不会开启子进程

11、编写rm.sh脚本,实现删除文件时移动文件

[root@centos7 scripts]# cat rm.sh 
#**************************************************************
#Author:                     28
#QQ:                         2*******1
#Date:                       2019-07-31
#FileName:                   rm.sh
#URL:                        http://51cto.uscwifi.cn
#Description:                The test script
#Copyright (C):              2019 Copyright ©  站点名称  版权所有
#************************************************************
RED="\033[1;31m"
GREEN="\033[1;32m"
END_COLOR="\033[0m"

. vars.sh
DESTDIR=/tmp/`date +%F_%T`

# 没有参数将报错退出
[ "$1" ] || { echo -e "${RED}Usage: rm.sh file...${END_COLOR}";exit 10; }

mkdir ${DESTDIR}
# 判断目录创建成功没有,没有成功就报错退出
[ ! "$?" -eq 0 ] && { echo -e "The Directory is existed.";exit 20; }

mv $* ${DESTDIR}
# 移动完成后打印提示
echo -e "${RED}$* is moved to ${DESTDIR}${END_COLOR}"

# 执行效果:
[root@centos7 scripts]# rm.sh /data/linuxaa
/data/linuxaa is moved to /tmp/2019-08-05_19:38:05

12、scp脚本,传输脚本到172.18.0.7

[root@centos7 scripts]# cat scp.sh 
#!/bin/bash
#**************************************************************
#Author:                     28
#QQ:                         868888688
#Date:                       2019-07-31
#FileName:                   scp.sh
#URL:                        http://51cto.uscwifi.cn
#Description:                The test script
#Copyright (C):              2019 Copyright ©  站点名称  版权所有
#************************************************************
scp $* [email protected]:/data/script38/

13、退出状态$?

使用$?判断程序是否执行成功,0表示成功,其他的值均为失败,1-255,不能超过255

14、test与中括号[]

用于判断,help test查看所有选项

-z 字符串是否为空
-f 是否存在并且是普通文件
-n 判断字符串是否为不空
-x 是否有执行权限
-d 目录
-e 是否存在

15、检查磁盘使用率,大于80%就报警

[root@centos7 scripts]# cat diskcheck28.sh 
#!/bin/bash
#**************************************************************
#Author:                     28
#QQ:                         868888688
#Date:                       2019-07-31
#FileName:                   diskcheck38.sh
#URL:                        http://51cto.uscwifi.cn
#Copyright (C):              2019 Copyright ©  站点名称  版权所有
#************************************************************
RED="\033[1;31m"
GREEN="\033[1;32m"
END_COLOR="\033[0m"

NUMBER_VALUE=8
DISK_USAGE=`df | grep '/dev/sd'| grep -Eo '[0-9]+%' | cut -d% -f1 | sort -n | tail -1`
WARNING="The disk will be full.Please Check."

[ $DISK_USAGE -ge ${NUMBER_VALUE} ] && { echo -e "${WARNING}" | mail -s "DISK WARNING" root; } || echo -e  "${GREEN}Disk is ok.${END_COLOR}"

16、判断某个文件是否存在并有无执行权限,没有的话加上执行权限

[root@centos7 scripts]# ll createuser.sh 
-rw-r--r-- 1 root root 879 Aug  1 16:19 createuser.sh
[root@centos7 scripts]# FILE=createuser.sh
[root@centos7 scripts]# [ -e "$FILE" -a ! -x "$FILE" ] && chmod +x $FILE
[root@centos7 scripts]# ll createuser.sh 
-rwxr-xr-x 1 root root 879 Aug  1 16:19 createuser.sh

17、grep匹配到内容返回值为0,匹配不到东西返回值为1

18、判断两个字符串是否一样用一个=

[root@centos7 scripts]# x=haha
[root@centos7 scripts]# y=hehe
[root@centos7 scripts]# [ "$x" = "$y" ] && echo "equal" || echo "not equal"
not equal
[root@centos7 scripts]# y=haha
[root@centos7 scripts]# [ "$x" = "$y" ] && echo "equal" || echo "not equal"
equal

19、判断两个数是否相等用-eq

20、ping脚本,判断某主机是否通

# -W 最少写2,不然总是误判为不通
[root@centos7 scripts]# cat hostping.sh
. vars.sh

read -p "Please input a ip: " HOST_IP
ping ${HOST_IP} -c2 -w2 > /dev/null

[ "$?" -eq 0 ] && echo -e "${GREEN}${HOST_IP} is up.${END_COLOR}" || echo -e "${RED}${HOST_IP} is down.${END_COLOR}"

# 执行效果
[root@centos7 scripts]# bash hostping.sh 
Please input a ip: 114.114.114.114
114.114.114.114 is up.

21、鸡兔同笼问题:训练有素;吹口哨;抬脚

# 脚本
[root@centos7 scripts]# cat chook_rabbit.sh 
read -p "Please input heads: " HEAD
read -p "Please input feet: " FOOT
RABBIT=$[(FOOT-2*HEAD)/2]
CHOOK=$[HEAD-RABBIT]
echo "RABBIT: $RABBIT"
echo "CHOOK: $CHOOK"
# 执行效果
[root@centos7 scripts]# bash chook_rabbit.sh 
Please input heads: 35
Please input feet: 96
RABBIT: 13
CHOOK: 22

22、if条件判断:5环之歌

[root@centos7 scripts]# cat 5circle.sh 
#!/bin/bash
. vars.sh

read -p "请输入你在第几环:" N
[[ ! "$N" =~ ^[1-9]+$ ]] && { echo "Please enter a digit.";exit 10; }
if [ "$N" -gt 6 ];then
    echo "Please enter a number in [1-6]"
    exit 20
elif [ "$N" -eq 6 ];then
    echo "你比5环多一环。"
elif [ "$N" -eq 5 ];then
    echo "555 555"
elif [ "$N" -eq 4 ];then
    echo "你比5环少一环。"
elif [ "$N" -eq 3 ];then
    echo "你比5环少二环。"
elif [ "$N" -eq 2 ];then
    echo "你比5环少三环。"
elif [ "$N" -eq 1 ];then
    echo "你比5环少四环。"
fi
[root@centos7 scripts]# bash 5circle.sh 
请输入你在第几环:5
555 555

23、case条件判断

一个脚本能接收一个参数,

参数为quit,则显示退出脚本,并正常退出

参数为yes,则显示继续执行脚本

其他值,非正常退出

[root@centos7 scripts]# cat test.sh 
case $1 in
    quit)
        echo "exit..."
    exit 0
    ;;
    yes)
        echo "continue..."
    ;;
    *)
        echo "error"
    exit 10
    ;;
esac
date

24、set -u与set -e

set -u,当脚本中变量未定义时报错,停止执行
set -e,当脚本中途出错,停止执行脚本

文件的查找与压缩

1、locate命令

作用:查找文件
原理:locate事先会将磁盘所有文件建立一个索引数据库,然后在里面查找文件位置
缺点:数据库不是实时的,有时需要手动更新数据库:updatedb
updatedb命令在服务器上要谨慎执行,当服务器文件比较多,updatedb命令会造成磁盘大量的读写,影响服务器性能

2、find实时查找

Linux系统中,删除/data/files⽬录下1周前修改过且⼤于10MB的⽂件?

[root@centos7 ~]# find /data/files/ -type f -ctime +7 -size 10M -exec rm {} \;

查看当前⽬录下30天以前.log结尾、⼤于1G的⽂件,并把它移动到/tmp下?

[root@centos7 ~]# find -type f -ctime +30 -name "*.log" -size +1G -exec mv {} /tmp/ \;

找出/data⽬录下所有的空⽬录,并移动到/tmp⽬录下?

[root@qqq ~]# find /data/ -type d -empty -exec mv {} /tmp \;

如何在/home⽬录找到⼤于1G的⽂件并删除?

[root@qqq ~]# find /home -type f -size +1G -exec rm {} \;

如何显⽰某个⽬录下的所有⽬录⽂件?

[root@qqq ~]# find /data/ -type d -ls

将/usr/local/web⽬录下⼤于100M的⽂件移动到/tmp⽬录下?

[root@qqq ~]# find /usr/local/web -type f -size +100M -exec mv {} /tmp/ \;

查找当前系统上没有属主或属组,且最近⼀个周内曾被访问过的⽂件。

[root@qqq ~]# find / -nouser -o -nogroup -atime -7 -type f -ls

查找/etc⽬录下所有⽤户都没有写权限的⽂件。

[root@qqq ~]# find /etc -type f -not -perm /222 -ls

关于perm用法:关于find的-perm

find 配合xargs会更好**

[root@qqq ~]# find / -type f -size +100M -print0 2>/dev/null| xargs -0 ls -lhS
-r--r--r--. 2 root root 140M Jun 30  2018 /media/CentOS_6.10_Final/images/install.img
-rw-------  1 root root 128M Jul 27 01:42 /sys/devices/pci0000:00/0000:00:0f.0/resource1
-rw-------  1 root root 128M Jul 27 01:42 /sys/devices/pci0000:00/0000:00:0f.0/resource1_wc
-rw-rw-r--. 1 qqq  qqq  121M Jul 17 05:10 /var/tmp/kdecache-qqq/kpc/plasma_theme_default.data
-rw-r--r--. 1 root root 103M Jul 15 09:30 /usr/share/icons/oxygen/icon-theme.cache
[root@qqq ~]# find / -type f -size +100M -print0 2>/dev/null| xargs -0 du -sm | sort -nr
140 /media/CentOS_6.10_Final/images/install.img
103 /usr/share/icons/oxygen/icon-theme.cache
# find的-print0:以0作为分隔符,看下面
[root@qqq ~]# find /root -type f -not -perm /111 -print0 | hexdump -C
00000000  2f 72 6f 6f 74 2f 61 6e  61 63 6f 6e 64 61 2d 6b  |/root/anaconda-k|
00000010  73 2e 63 66 67 00 2f 72  6f 6f 74 2f 2e 49 43 45  |s.cfg./root/.ICE|
00000020  61 75 74 68 6f 72 69 74  79 00 2f 72 6f 6f 74 2f  |authority./root/|
# 0是ascii码中的第一个
       Oct   Dec   Hex   Char                        Oct   Dec   Hex   Char
       ------------------------------------------------------------------------
       000   0     00    NUL '\0'                    100   64    40    @
# xargs的-0,可以看man手册
使用null字符(00)作为分隔符,默认xargs以空白作为分隔符

关于perm用法:关于find的-perm

3、压缩

compress  ; compress -d
gzip      ; gzip -d(gunzip)
xz        ; xz -d
bzip2     ; bzip2 -d
zip       ; unzip       (可以压缩文件夹)
tar cf    ; tar xf      (可以压缩文件夹)
# 可以借助管道,重定向,输入输出流-来配合使用
# tar的-C可以指定解压目录
tar xf 1.tar.gz -C /tmp
# 使用dd创建的大文件压缩后可以很小很小

cpio;cpio2rpm等等不常用

4、切割文件

splite切割文件