指令碼 只保留最近十個備份檔案

2021-10-06 07:27:40 字數 518 閱讀 1982

我匹配的是包含buckup的,因為也許當前資料夾有可能有其他檔案

ls -lrt 代表檢視檔案按照時間排列,然後倒敘,就是從最老的到最新的,由上往下

剛開始想使用for來做刪除操作,然後發現xargs 直接就可以了,比較方便,就把for注釋了

count=

`ls -lrt |

awk'/buckup/ '

|wc -l`if[

$count -gt 10 ]

;then

del=$[

$count-10]

#echo $count

#echo $del

#for i in `ls -lrt | awk '/buckup/ ' | head -$`;

#do# echo $i

#done

ls -lrt |

awk'/buckup/ '

|head -$

|xargs

rmfi

shell指令碼(保留最近N天的備份)

bin bash 保留最近n天的備份 2019年6月16日11 32 59 需求 檔案備份格式為date f h m 節假日不備份 無論過幾個節假日,始終保留最新n天的備份 模擬備份 mkdir pwd test touch pwd test date d 1 day ago f h m tar.g...

關於保留最近三天檔案的shell指令碼

bin sh day bin date y m d count usr bin find home ledscr backup mtime 1 wc l usr bin find home ledscr backup mtime 1 delete echo day count 注 1 find mt...

python字串只保留漢字

defis chinese uchar 判斷乙個 unicode 是否是漢字 ifuchar u u4e00 anduchar u u9fa5 returntrue else returnfalse defis number uchar 判斷乙個 unicode 是否是數字 ifuchar u u0...