6个你可能不知道的bash 小秘笈
2016-10-20 09:27
155 查看
bash 是一个为GNU计划编写的Unix shell。它的名字是一系列缩写:Bourne-Again SHell — 这是关于Bourne shell(sh)的一个双关语(Bourne again / born again)。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
3sed删除特定的行
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就是输出全部
6sort 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函数你可能不知道的一些事情(译)
- 你可能不知道的Linux/GNU bash sort多列排序功能
- CSS你可能还不知道的一些知识点
- 关于Promise:你可能不知道的6件事
- oracle层次化查询,你可能不知道的地方
- 你可能不知道 Google 最近的「小动作」
- CSS中你可能不知道的单位
- 你可能不知道的Shell--转
- c++ --> 你可能不知道的c++
- 关于Node.js中Buffer的一些你可能不知道的用法
- 你可能不知道的Shell
- 30个通过internet可以做到的但是你可能不知道的事
- 你可能不知道的一些JavaScript 奇技淫巧
- 你可能不知道的5种 CSS 和 JS 的交互方式
- 一大波你可能不知道的 Linux 网络工具
- JAVA SE中你可能不知道的知识点
- 又一波你可能不知道的 Linux 命令行网络监控工具
- 你可能不知道的10个JavaScript小技巧
- 你可能不知道的10个JavaScript小技巧
- 你可能不知道的Shell