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
run 如下命令后:
find /mnt/daily/LotusLive -mindepth 1 -maxdepth 1 -type d | sort | awk -F '[/]' '{print $5}' | awk -F '[_]' '/SC[234]/{print $1}' | uniq
显示:
SC20.0
SC30.0
SC30.16
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
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就是输出全部
./com.rcloud.appnodemessagepool.MSG_NODE_4/conf/envconfs.conf
./com.rcloud.appnodemessagepool.MSG_NODE_5/conf/envconfs.conf