linux-shell下删除当前文件夹中按时间排序的前N个文件夹

#!/bin/sh

ls -lrt| awk '{if(NR<4 && NR!=1) printf("rm -rf %s
",$8)}' >rm2.sh

chmod 755 rm2.sh

./rm2.sh

rm rm2.sh

#!/bin/sh

for i in `ls -lthr | head -3 |grep -v 'total'`

do

 rm -rf  $i

done;

参考: https://blog.csdn.net/osyun/article/details/6650519

原文地址:https://www.cnblogs.com/clovershell/p/14062630.html