命令1 | 命令2,命令1的输入作为命令2的输入
执行命令:ll /etc | head -5

执行命令:cat /etc/profile | tail -5

grep [选项参数] 文件
执行命令:ll /etc | grep python

执行命令:ll /etc | grep -c python

执行命令:cat /etc/profile | grep dev

执行命令:cat /etc/passwd | grep how*

执行命令:grep hi d*
执行命令:grep ‘hadoop’ demo.txt demo1.txt
执行命令:grep ‘[a-z]{7}’ demo.txt
执行命令:grep ‘[a-z]{6}’ demo.txt
find 路径 [选项参数]
执行命令:find /etc/sysconfig -type ‘d’

检查是否查找成功

执行命令:find /etc/sysconfig -type ‘l’

执行命令:find /etc/sysconfig -type ‘f’

执行命令:find /etc/sysconfig -name ‘network’
执行命令:find /etc/sysconfig -name ‘net*’ (可使用通配符)

执行命令:find /etc/sysconfig -size 15c(等于15字节)

执行命令:find /etc/sysconfig -size +10k(大于10240个字节)

执行命令:find /etc/sysconfig -size -20c (小于20个字节)

执行命令:find /etc/sysconfig -perm ‘777’ (权限字符串:rwxrwxrwx)

执行命令:find /etc/sysconfig -perm ‘755’ (权限字符串:rwxr-xr-x)

sed “[action]” [filename]
预备工作:创建demo.txt

执行命令:sed “s/hello/HELLO/” demo.txt

执行命令:sed “2,3s/hello/HELLO/2” demo.txt

执行命令:sed “2s/hello/HELLO/g” demo.txt

执行命令:sed “s/hello/HELLO/g” demo.txt > demo1.txt

执行命令: sed -i “s/hello/hi/g” demo.txt

执行命令:sed “2 i I love Linux” demo.txt

执行命令:sed “2 a Linux is fun and I love it” demo.txt

执行命令:sed ‘2d’ demo.txt

执行命令: sed ‘2,3d’ demo.txt

执行命令:sed ‘d’ demo.txt

执行命令:sed ‘/scala/g’ demo.txt

tail [选项参数] 文件名
执行命令:tail -n 4 anaconda-ks.cfg

执行命令:tail -c 4 love.txt

sort [选项参数] 文件
预备工作:创建ips.txt文件

执行命令:sort ips.txt,按字典排序法升序排列

执行命令:sort -r ips.txt,按字典排序法降序排列

执行命令:sort -t ‘.’ -k 4 ips.txt,升序排列

执行命令:sort -t ‘.’ -k 4 -r ips.txt,降序排列

cut [选项参数] 文件名
执行命令:cut -c 7 ips.txt

执行命令:cut -b 7 ips.txt

执行命令:cut -d ‘.’ -f 4 ips.txt,提取第4节内容

执行命令:cut -d ‘.’ -f 2 ips.txt,提取第2节内容

history [选项参数]
执行命令:history
执行命令:history 10 (写成history -n 10也是一样效果)

执行命令:history | head -10

执行命令:history | grep vim

查看历史第5条命令
执行命令:!5

执行命令:!!

执行命令:!his

执行命令:history -w myhis

执行命令:cat myhis | tail -5

查看第5条历史明令
执行命令:history -d 5

执行命令:history -c

执行命令:history -r myhis

执行命令:history | head -10

创建脚本文件,执行命令:vim /home/shell.sh

此时,shell.sh对于所有者而言,只有读和写的权限,并不是可执行的脚本

shell.sh文件必须具备可读与可执行(rx) 的权限
增加shell.sh的写权限,执行命令:chmod u+x /home/shell.sh


绝对路径方式执行脚本
执行命令:/home/shell.sh

相对路径方式执行脚本
执行命令:cd /home
执行命令:./shell.sh (.表示当前目录)

执行命令:source shell.sh

执行命令:bash shell.sh

执行命令: sh shell.sh

执行命令:vim shell01.sh

执行命令:chmod u+x shell01.sh,增加可执行权限

执行命令:./shell01.sh

执行命令:vim shell02.sh

执行命令:chmod u+x shell02.sh

执行命令:./shell02.sh
