zoukankan      html  css  js  c++  java
  • shell-保留文件系统下剩余指定数目的文件

     1 #!/bin/bash
     2 ##############################################
     3 #Author:rubyzhu
     4 #Date:2013.1.29
     5 #Version:1.0
     6 #Update:2013.1.30
     7 #Description: Back up your files
     8 ##############################################
     9 
    10 #shell Variable
    11 path_source=/mnt/fifth/shell
    12 path_backup=/mnt/fifth/backup/shellbackup
    13 path_delete=/mnt/fifth/tmp/rubbish/
    14 limit_num=15
    15 
    16 fileBackup()
    17 {
    18 set -x
    19 #back up
    20 #cp -r $1 $2/shell-`date +%Y-%m-%d-%H-%M-%S`
    21 count=`ls $1 | wc -w`
    22 
    23 if [ "$count" -gt "$3" ];then
    24     echo "-----------------limit is : $3 ----------------------"
    25     echo "-----------------The number of files is : $count -------"
    26     num=`expr $count - $3`
    27     echo "-----------------The excess number of files is : $num ---------"
    28 #move
    29     ls $1 -1rt | head -n $num|xargs -n1 -i mv $1/{} $2
    30     set +x
    31     ls -1rt $2
    32     echo "-----------------Moving end!-----------------"
    33 else
    34     ls -1rt $2
    35     echo "-----------------The file is too little!-------------------"
    36 fi
    37 
    38 }
    39 
    40 #back up shell
    41 fileBackup $path_backup $path_delete $limit_num
  • 相关阅读:
    AtCoder Grand Contest 001F Wide Swap
    生成函数/母函数入门学习
    树的点分治入门小结
    树链剖分入门小结
    有重复元素的全排列
    二项式界
    二项系数
    排列问题、组合问题
    容斥原理
    P3372 【模板】线段树 1
  • 原文地址:https://www.cnblogs.com/zhuhongbao/p/3402395.html
Copyright © 2011-2022 走看看