歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> bash 小秘笈

bash 小秘笈

日期:2017/3/3 17:48:18   编辑:學習Linux

bash 小秘笈

bash 小秘笈


導讀bash 是一個為GNU計劃編寫的Unix shell。它的名字是一系列縮寫:Bourne-Again SHell — 這是關於Bourne shell(sh)的一個雙關語(Bourne again / born again)。bash我們很常用,但是更高級的用法你知道嗎?看完下面的示例,你一定會有啟發的。

bash 小秘笈bash 小秘笈

1. 按時間先後,列出最後的十個目錄
ls /mnt/daily/Concord/main -sort -t | awk /_[0-9]+-[0-9]/'{print $NF}' | tail -10/mnt/daily/LotusLive目錄內容如下:SC10.0_Docs :dirSC10.0_DocsProxy :dirSC20.0_Docs :dirSC20.0_DocsProxy :dirSC30.0_Docs :dirSC30.0_DocsProxy :dirSC30.16_Docs :dirSC30.16_Viewer :dirtsm_backup :file
2. 遞歸刪除空目錄
# $1必須是絕對路徑crurl=$1func_hdir(){echo $crurlcd $crurlfor aitem in `ls -l | grep "^d" | awk '{print $9}'`; docrurl=$crurl/$aitemfunc_hdir $aitemdonedirc=`ls $crurl`if [ "$dirc" = "" ]thenecho $crurlrm -rf $crurlficrurl=${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天創建的目錄
find /mnt/daily/Concord/main -mindepth1 -maxdepth 1 -type d -mtime -5-mtime 最大數是8,超過8就是輸出全部
6. sort by 特定列
如當前工作中的應用,以MSG_NODE_%d排序,可用如下命令find . -type f -name envconfs.conf | grep -v "chatroom"| grep "appnodemessagepool"| sort -t '.' -k4find . -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

原文來自:https://yq.aliyun.com/articles/61017?spm=5176.100239.bloglist.92.86B7DB

本文地址:http://www.linuxprobe.com/bash-list.html


http://xxxxxx/Linuxjc/1184688.html TechArticle

Copyright © Linux教程網 All Rights Reserved