在使用 linux命令时,如果不小心输入了 "(左双引号),就会出现如下的显示:
# "
> q
> quit
> exit
> off
> reboot
> shutdown
>
>
>
不管你输入什么常用命令,都无法退出该“模式”。我们暂且称他为 模式,或者 “状态”更合适。
其实,发生上述情况时,只要输入 和其一般匹配的字符即可,如上面的"(左引号),只要
输入"(右引号),使之成对即可退出 该状态。
if 同理。。
突然发现linux命令 太有意思了。。。
获取进程init信息:
1. 如果直接用ps | grep "init",那么会有两条信息,具体请参考linux shell原理
# ps | grep "init" 1 root 1720 S init 919 root 1716 S grep init #
2. ps | grep -v grep | grep "init"只显示名为init的线程信息
# ps | grep -v grep | grep "init" 1 root 1720 S init #
检测网卡eth0是否down掉了:ifconfig + grep
ifconfig | grep eth0
没有信息显示则down掉了
获取网卡eth0的网络信息(不管网卡eth0是否down掉都行):ifconfig + grep
ifconfig eth0 | grep "inet"
截取以特定字符分割的字符串:(默认为tab键)cut
ip=$(ifconfig eth0 | grep "inet" | cut -d: -f 2)
获取进程hiIpc的信息:
ps | grep -v grep | grep hiIpc | awk '{printf "%d %s %s\n",$1,$4,$5}'
获取所有的网络信息(转):
default_route=$(ip route show)
default_interface=$(echo $default_route | sed -e 's/^.*dev \([^ ]*\).*$/\1/' | head -n 1)
address=$(ip addr show label $default_interface scope global | awk '$1 == "inet" { print $2,$4}')
#ip address
ip=$(echo $address | awk '{print $1 }')
ip=${ip%%/*}
#broadcast
broadcast=$(echo $address | awk '{print $2 }')
#mask address
mask=$(route -n |grep 'U[ \t]' | head -n 1 | awk '{print $3}')
#gateway address
gateway=$(route -n | grep 'UG[ \t]' | awk '{print $2}')
#dns
dns=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
echo ip:$ip,mask:$mask,broadcast:$broadcast,gateway:$gateway,dns:$dns