阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

bash 小秘笈

30次阅读
没有评论

共计 1368 个字符,预计需要花费 4 分钟才能阅读完成。

导读 bash 是一个为 GNU 计划编写的 Unix shell。它的名字是一系列缩写:Bourne-Again SHell — 这是关于 Bourne shell(sh)的一个双关语(Bourne again / born again)。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 :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 天创建的目录
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 '.' -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

阿里云 2 核 2G 服务器 3M 带宽 61 元 1 年,有高配

腾讯云新客低至 82 元 / 年,老客户 99 元 / 年

代金券:在阿里云专用满减优惠券

 

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2024-07-24发表,共计1368字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中