實現自動變色功能
color=$[RANDOM%7+31];echo -e “\033[${color}mred color\033[0m”
color=`seq 31 37 | sort -R |head -1`;echo -e “\033[1;5;${color}mred color\033[0m”
————————————————————————————————————————–
用echo命令打印帶有色彩的文字:
文字色:
echo -e “\e[1;31mThis is red text\e[0m”
This is red text
\e[1;31m 將顏色設置為紅色
\e[0m 將顏色重新置回
顏色碼:重置=0,黑色=30,紅色=31,綠色=32,黃色=33,藍色=34,洋紅=35,青色=36,白色=37
背景色:
echo -e “\e[1;42mGreed Background\e[0m”
Greed Background
顏色碼:重置=0,黑色=40,紅色=41,綠色=42,黃色=43,藍色=44,洋紅=45,青色=46,白色=47
文字閃動:
echo -e “\033[37;31;5mMySQL Server Stop…\033[39;49;0m”
紅色數字處還有其他數字參數:0 關閉所有屬性、1 設置高亮度(加粗)、4 下劃線、5 閃爍、7 反顯、8 消隱
—————————————————————————————————————————-
顯示ifconfig命令結果中所有IPv4地址
ifconfig |egrep -o “\<(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>”
—————————————————————————————————————————-
生成指定位數的隨機口令
cat /dev/urandom |tr -dc ‘[:alnum:]_’ |head -c20
lwpqHp67hWdYVwnogmKv
tr -dc ‘[:alnum:]_’ < /dev/urandom |head -c20
openssl rand -base64 30 |head -c20
————————————————————————————————————————–
刪除haha的家目錄,恢復之(權限,所有者組,數據)
cp -r /etc/skel /home/haha
chown -R haha:haha /home/haha
chmod 700 /home/haha
————————————————————————————————————————–
將文件/etc/centos-release中每個單詞(由字母組成)顯示在獨立的一行,并無空行
tr -sc ‘a-zA-Z’ ‘\n’ < /etc/centos-release
tr -dc ‘a-zA-Z ‘ < /etc/centos-release |tr -s ‘ ‘ ‘\n’
————————————————————————————————————————–
將指定文件中0-9分別替代成a-j
tr 0-9 a-j < file.txt
————————————————————————————————————————–處理字符串“xt.,l 1 jr#!$mn2 c*/fe3 uz4”,只保留其中的數字和空格
echo ‘xt.,l 1 jr#!$mn2 c*/fe3 uz4’ | tr -dc ‘[:digit:] \n’
————————————————————————————————————————–刪除去Windows文本文件中的‘^M’字符
tr -d ‘\r’ < win.txt > win2.txt
tr -d ‘\15’ < win.txt > win2.txt
顯示ifconfig命令結果中所有IPv4地址
ifconfig ens33|grep -o “\<\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\>”
————————————————————————————————————————–
用正則表達式表示出QQ號
grep “\<[0-9]\{5,11\}\>”
————————————————————————————————————————–
用正則表達式表示出身份證號
echo ‘37132519910610755X’ |grep -io “\<[0-9]\{17\}[0-9x]\>”
————————————————————————————————————————–
用正則表達式表示郵箱: x@y.z.m
echo ‘.zL_d-55.4e@vip.168.com.’|grep -o “\<[[:alnum:]_-\.]\+@\([[:alnum:]]\+\.\)\{1,2\}[[:alnum:]]\+\>”
————————————————————————————————————————–
復制/etc/profile至/tmp/目錄,用查找替換命令刪除/tmp/profile文件中的行首的空白字符
:%s/^[[:space:]]*//g
————————————————————————————————————————–
復制/etc/rc.d/init.d/functions文件至/tmp目錄,用查找替換命令為/tmp/functions的每行開頭為空白字符的行的行首添加一個#號
:%s/^[[:space:]]/#&/g
本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/89784