linux-shell下删除当前文件夹中按时间排序的前N个文件夹
#!/bin/sh ls -lrt| awk '{if(NR<4 && NR!=1) printf("rm -rf %s\n",$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