cat /etc/shells 说明: 显示 /etc/shells 文件内容,即列出当前系统可用shell

GNU/bash shell特点
1. 命令和文件自动补齐
2. 命令历史记忆功能上下键、!number、!string、!$、!!、^R
3. 别名功能 alias、unalias cp、~username/.bashrc、\cp -rf /etc/hosts.
4. 快捷键^R、^D、^A、^E、^L、^U、^K、^Y、^S、^Q
5. 前后台作业控制 &、nohup、^C、^Z、bg%1、fg%1、kill %3、screen
6. 输入输出重定向 0,1,2 > >> 2> 2>> 2>&1 &> cat < /etc/hosts cat <file1 <
[root@tianyun ~]# ll /dev/std*
lrwxrwxrwx 1 root root 15 Sep 1 2015 /dev/stderr -> /proc/self/fd/2
lrwxrwxrwx 1 root root 15 Sep 1 2015 /dev/stdin -> /proc/self/fd/0
lrwxrwxrwx 1 root root 15 Sep 1 2015 /dev/stdout -> /proc/self/fd/1
7. 管道| tee
ip addr |grep 'inet ' |grep eth0
ip addr |grep 'inet '|tee test|grep eth0覆盖
ip addr |grep 'inet '|tee -a test|grep eth0-a 追加
df |grep '/$'
df|tee df.txt|grep '/$'
[root@tianyun ~]# date > date.txt
[root@tianyun ~]# date |tee date.txt
Fri Aug 25 15:30:20 CST 2017
8. 命令排序
;不具备逻辑判断
cd; eject
&& ||具备逻辑判断
./configure && make && make install(命令返回值 echo $?)
mkdir /var/111/222/333 && echo ok
mkdir -p /var/111/222/333 && echo ok
ls /home/111/222/333/444 || mkdir -p /home/111/222/333/444
[-d /home/111/222/333/444 ] || mkdir -p /home/111/222/333/444
ping -c1 10.18.42.1 &>/dev/null && echo up || echo down
============================================================
注意:
command &后台执行
command &>/dev/null混合重定向(标准输出1,错误输出2)
command1 && command2命令排序,逻辑判断
============================================================
9. shell通配符(元字符)表示的不是本意
*匹配任意多个字符 ls in* rm -rf * rm -rf *.pdf find / -iname "*-eth0"
?匹配任意一个字符 touch love loove live l7ve; ll l?ve
[]匹配括号中任意一个字符 [abc] [a-z] [0-9] [a-zA-Z0-9] [^a-zA-Z0-9] ll l[io]ve ll l[^a-z]ve ll /dev/sd[a-z]
()在子shell中执行(cd /boot;ls) (umask 077; touch file1000)
{} 集合touch file{1..9}
# mkdir /home/{111,222}mkdir -pv /home/{333/{aaa,bbb},444}
# cp -rv/etc/sysconfig/network-scripts/ifcfg-eth0/etc/sysconfig/network-scripts/ifcfg-eth0.old
# cp -rv/etc/sysconfig/network-scripts/{ifcfg-eth0,ifcfg-eth0.old}
# cp -rv/etc/sysconfig/network-scripts/ifcfg-eth0{,.old}
\转义符,让元字符回归本意
# echo *
# echo\*
# touch yang\sheng
mkdir\\
echo -e "atb"
echo -e "a\tb"
echo -e "anb"
echo -e "a\nb"
网友评论