Linux 相關小技巧
修改提示行
進入目錄 ![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
建立 yanse.sh nano yanse.sh![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
修改顏色命令:
PS1="[\e[1;36m][\u@\h \W ]\$[\e[0m]"
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
保存 退出
exit
效果:
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
------------------------------------------------------------
修改登陸前提示 /etc/issue
cat /etc/issue 查看修改登陸前提示 /etc/issue![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
尋找幫助
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
根據本身須要進行修改
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
效果:
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
------------------------------------------------------------
修改motd 登陸提示信息
刪除系統motd文件
rm -f /etc/motd
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
進入 /etc 目錄
rz命令 從windows系統傳入文件
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
上傳成功
exit
效果圖:
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
------------------------------------------------------------
CentOS7中 ls /misc/cd 不能掛載的解決方法
查看設置
systemctl status autofs
運行開啓服務
systemctl start autofs
設置開機自啓動
systemctl enable autofs
效果圖:![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
------------------------------------------------------------
查看目錄顏色 cat /etc/DIR_COLORS
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
------------------------------------------------------------
實現錄屏功能 script -t 2> time.log -a cmd.session
輸入命令 錄屏開始
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
簡單輸入幾個命令做爲測試
結束 exit
回看記錄: cat cmd.session scriptreply time.log cmd.session
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
scriptreply time.log cmd.session![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
------------------------------------------------------------
掛載U盤 echo '- - -' > /sys/class/scsi_host/host2/scan
echo '- - -' > /sys/class/scsi_host/host2/scan
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
------------------------------------------------------------
刪除歷史記錄
找到 .bash_history文件
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
清除內存中的歷史 (注意順序)
rm .bash_history
history -c
------------------------------------------------------------
screen 實現同屏
centos7 須要安裝screen包
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
建立screen
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
查看screen screen -ls
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
鏈接
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
效果
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
剝離 ctrl+A D
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
重連 screen -r help
------------------------------------------------------------
mail 發送郵件
發郵件
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
收郵件
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
------------------------------------------------------------
誤刪除用戶後恢復的方法
建立用戶useradd test1
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
刪除用戶rm -rf /home/test1
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
mkdir /home/test1
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
cp -r /etc/skel/. /home/test1
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
如圖
------------------------------------------------------------
更改帳戶加密算法
cat /etc/login.defs
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
authconfig --passalgo=sha256 --update
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
查看shadow
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
shadow裏 root帳戶變爲$5
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
------------------------------------------------------------
附加組相關文件位置 以及添加組成員、刪除組成員
/etc/group:附加組及其屬性信息 組名 口令 組ID 組成員
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
/etc/gshadow:附加組組密碼及其相關屬性 組名 組口令 組成員
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
以上兩個文件必須同步 能夠查看一下man幫助說明
man gshadow
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
通常不用手工改 用命令去改
添加用戶到組中 usermod -G test root
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
從test組中刪除用戶 groupmems -g test -d root![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
------------------------------------------------------------
獲取IP
方法1 ifconfig ens33|head -n2 | tail -n1| tr -s " "|cut -d" " -f3
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
方法2 ifconfig ens33|grep -o '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}'|head -n1
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
方法3 ifconfig ens33|grep -w "inet" |grep -o "[0-9.]{7,15}" |head -n1
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
方法4 ifconfig ens33|grep -o "inet [0-9.]+"|cut -d " " -f2
方法5 ifconfig eth0|grep -w inet |grep -o '([0-9]{1,3}.){3}[0-9]{1,3}'|head -n1
方法6 ifconfig eth0|grep -w inet |grep -Eo '([0-9]{1,3}.){3}[0-9]{1,3}'|head -n1
![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
方法7 ifconfig ens33|head -n2|tail -n1|tr -s " " |cut -d" " -f3
------------------------------------------------------------
取隨機數10位
tr -dc '[:alnum:]' < /dev/urandom | head -c10![Linux 相關小技巧](http://static.javashuo.com/static/loading.gif)
統計rpm 包數量
ls /misc/cd/Packages/|grep -o "[^.]+.rpm$"|cut -d. -f1|sort |uniq -c
ls /misc/cd/Packages/*.rpm |rev|cut -d. -f2|rev|sort |uniq -c
------------------------------------------------------------
grep 取 basename dirname
echo /etc/rc.d/init.d/functions|egrep -o '[^/]+/?$'
echo /etc/rc.d/init.d/functions|egrep -o "^.*/"
------------------------------------------------------------
磁盤使用率
df |grep "^/dev/sd"|tr -s " " % |cut -d% -f5|sort -nr
df|grep "/dev/sd" |grep -Eo "[0-9]{1,3}%"|grep -Eo "[0-9]{1,3}" |sort -nr
歡迎關注本站公眾號,獲取更多信息