shell删除保留最新10个文件
最新按照哪个时间来, 创建时间, 访问时间, 还是修改时间? 命令参考如下, 可以写成脚本定时调度.
按照文件生成时间:
stat --printf="%W,%n\n" aaa* | sort -r | tail +11 | awk -F"," '{print "rm "$2";"}' | sh
stat --printf="%W,%n\n" bbb* | sort -r | tail +11 | awk -F"," '{print "rm "$2";"}' | sh
stat --printf="%W,%n\n" ccc* | sort -r | tail +11 | awk -F"," '{print "rm "$2";"}' | sh
按照文件修改时间:
stat --printf="%Y,%n\n" aaa* | sort -r | tail +11 | awk -F"," '{print "rm "$2";"}' | sh
stat --printf="%Y,%n\n" bbb* | sort -r | tail +11 | awk -F"," '{print "rm "$2";"}' | sh
stat --printf="%Y,%n\n" ccc* | sort -r | tail +11 | awk -F"," '{print "rm "$2";"}' | sh
按照文件访问时间:
stat --printf="%X,%n\n" aaa* | sort -r | tail +11 | awk -F"," '{print "rm "$2";"}' | sh
stat --printf="%X,%n\n" bbb* | sort -r | tail +11 | awk -F"," '{print "rm "$2";"}' | sh
stat --printf="%X,%n\n" ccc* | sort -r | tail +11 | awk -F"," '{print "rm "$2";"}' | sh