隨筆記錄(持續(xù)更新)

永久修改主機名

[root@kangxu ~]# hostnamectl set-hostname cuihua
[root@kangxu ~]# bash
[root@cuihua ~]# 

重要面試題

使用shell腳本,找出/etc目錄下以.conf結(jié)尾文件復制到/tmp下面
方法1.

find /etc/ -name '*.conf' -type f|xargs -i cp {} /tmp/

方法2.

find /etc/ -name '*.conf' -type f -exec cp {} /tmp \;

方法3.

cp $(find /etc/ -name '*.conf' -type f ) /tmp

方法4.

find /etc/ -name '*.conf' -type f |xargs cp -t /tmp/

打包備份/etc目錄到/backup下面 保證每天備份的壓縮包名字不同

[root@oldboy ~]# tar zcf /backup/etc-'date +%F'.tar.gz /etc
tar: Removing leading `/' from member names
[root@oldboy ~]# ls /backup
etc-2019-04-19.tar.gz

取出網(wǎng)卡ip地址:

ip a s eth0
方法1 sed 正則

[root@oldboyedu59 ~]# ip a s eth0 |sed -n '3p' |sed 's#^.*t ##g'
10.0.0.201/24 brd 10.0.0.255 scope global eth0
[root@oldboyedu59 ~]# ip a s eth0 |sed -n '3p' |sed 's#^.*t ##g'|sed 's#/.*$##g'
10.0.0.201

方法2 sed 后向引用

[root@oldboyedu59 ~]# ip a s eth0 
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:ff:79:0e brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.201/24 brd 10.0.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:feff:790e/64 scope link 
       valid_lft forever preferred_lft forever
[root@oldboyedu59 ~]# ip a s eth0 |sed -n 3p 
    inet 10.0.0.201/24 brd 10.0.0.255 scope global eth0
[root@oldboyedu59 ~]# ip a s eth0 |sed -n 3p |sed -r 's#^.*t (.*)/.*$#\1#g'
10.0.0.201
[root@oldboyedu59 ~]# ip a s eth0 |sed -n 3p |sed -r 's#(^.*t )(.*)(/.*$)#\1#g'
    inet 
[root@oldboyedu59 ~]# ip a s eth0 |sed -n 3p |sed -r 's#(^.*t )(.*)(/.*$)#\3#g'
/24 brd 10.0.0.255 scope global eth0

stat /etc/hosts

取出結(jié)果中的644

[root@cuihua ~]# stat /etc/hosts|sed -n '4p'|sed -r 's#^.*\(0([0-9]+)/.*$#\1#g'
644
[root@cuihua ~]# 
[root@cuihua ~]# stat /etc/hosts|sed -n '4p'|sed -r 's#^.*\(0(.*)/-.*$#\1 #g'
644 

Linux下面生成隨機密碼方法

方法1 tr + head

[root@oldboyedu59 ~]# tr -cd 'a-zA-Z0-9' </dev/urandom |head -c8
B0iV36fZ[root@oldboyedu59 ~]# 

方法2 date +md5sum/sha512sum + head

[root@oldboyedu59 ~]# date +%N
211379317

date +%N |md5sum |head -c10
[root@oldboyedu59 ~]# date +%N|md5sum |head -c8
888b0ea8[root@oldboyedu59 ~]# 

方法3 RANDOM環(huán)境變量

RANDOM生成隨機數(shù)字
echo $RANDOM

RANDOM + md5sum

RANDOM +數(shù)字

[root@oldboyedu59 ~]# echo $((RANDOM+10000000))
10017665
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容