bash 小秘笈

Crq
Crq
管理员
1964
文章
0
粉丝
Linux教程评论33字数 298阅读0分59秒阅读模式
摘要bash 是一个为GNU计划编写的Unix shell。它的名字是一系列缩写:Bourne-Again SHell — 这是关于Bourne shell(sh)的一个双关语(Bou...

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

weinxin
我的微信
微信号已复制
我的微信
这是我的微信扫一扫
 
Crq
  • 本文由 Crq 发表于2025年3月3日 15:32:02
  • 转载请注明:https://www.cncrq.com/13287.html
smem – Linux 内存监视软件 Linux教程

smem – Linux 内存监视软件

Linux 系统的内存管理工作中,内存使用情况的监控是十分重要的,在各种 Linux 发行版上你会找到许多这种工具。它们的工作方式多种多样,在这里,我们将会介绍如何安装和使用这样的...
Zookeeper集群搭建 Linux教程

Zookeeper集群搭建

由于公司缓存方案改进,准备采用codis集群作为主要的缓存解决方案(codis:国内豌豆荚开发的redis集群解决方案,已开源,github地址:https://github.co...
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证