shell脚本实现仅保留某目录下最新的两个文件
1 #!/bin/sh 2 3 export DS_DIR=/home/cxy/test 4 5 if [ ! -d $DS_DIR ]; then 6 mkdir $DS_DIR 7 else 8 echo "$DS_DIR is not existed!" 9 fi 10 11 cd $DS_DIR 12 if [ $(ls -l | grep "install-*" | wc -l) > 3 ]; then 13 echo "more than 2 dst_files in $DS_DIR" 14 rm -r $(ls -rt | head -n2) 15 fi
勤苦修行得自在,道力有边边亦无边!