在使用 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