新聞中心
這里有您想知道的互聯(lián)網營銷解決方案
bash高級使用方法
linux的發(fā)布版本之一——Redhat/CentOS——系統(tǒng)默認安裝的shell叫做bash,即Bourne Again Shell,它是sh(Bourne Shell)的增強版本。Bourn Shell 是最早行起來的一個shell,創(chuàng)始人叫Steven Bourne,為了紀念他所以叫做Bourn Shell,檢稱sh,本篇文章重點為大家分享一下bash高級使用方法。

創(chuàng)新互聯(lián)建站是一家專業(yè)提供湘橋企業(yè)網站建設,專注與成都做網站、網站制作、成都外貿網站建設、H5網站設計、小程序制作等業(yè)務。10年已為湘橋眾多企業(yè)、政府機構等服務。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進行中。
1. 按時間先后,列出最后的十個目錄
ls /mnt/daily/Concord/main -sort -t | awk /_[0-9]+-[0-9]/'{print $NF}' | tail -10
/mnt/daily/LotusLive目錄內容如下:
SC10.0_Docs :dir
SC10.0_DocsProxy :dir
SC20.0_Docs :dir
SC20.0_DocsProxy :dir
SC30.0_Docs :dir
SC30.0_DocsProxy :dir
SC30.16_Docs :dir
SC30.16_Viewer :dir
tsm_backup :file
2. 遞歸刪除空目錄
# $1必須是絕對路徑
crurl=$1
func_hdir(){
echo $crurl
cd $crurl
for aitem in `ls -l | grep "^d" | awk '{print $9}'`; do
crurl=$crurl/$aitem
func_hdir $aitem
done
dirc=`ls $crurl`
if [ "$dirc" = "" ]
then
echo $crurl
rm -rf $crurl
fi
crurl=${crurl%/*}
}
func_hdir
3. sed刪除特定的行
sed -e '/^[ ]*$/d' osgi_file > target_file //刪除空行
sed -d '/concord/d' osgi_file>target_file//包涵concord的行
4. 輸出最新的N個目錄
find /mnt/daily/Concord/main -mindepth 1 -maxdepth 1 -type d -printf "%T@%Tx %p" | sort -n -r | head -N
5. 輸出最近5天創(chuàng)建的目錄
find /mnt/daily/Concord/main -mindepth1 -maxdepth 1 -type d -mtime -5
-mtime 最大數(shù)是8,超過8就是輸出全部
6. sort by 特定列
如當前工作中的應用,以MSG_NODE_%d排序,可用如下命令
find . -type f -name envconfs.conf | grep -v "chatroom"| grep "appnodemessagepool"| sort -t '.' -k4
find . -type f -name envconfs.conf|grep "appnodemessagepool"|sort -t '/' -k2
./com.rcloud.appnodemessagepool.MSG_NODE_3/conf/envconfs.conf
./com.rcloud.appnodemessagepool.MSG_NODE_4/conf/envconfs.conf
./com.rcloud.appnodemessagepool.MSG_NODE_5/conf/envconfs.conf
本文名稱:bash高級使用方法
轉載源于:http://www.dlmjj.cn/article/djgdioh.html


咨詢
建站咨詢
