rm - bash script that delete file according to date in file name -


i busy writing bash script can delete file according date in file name example xxxxxxxxx140516.log. should delete file day after 16 of may 2014. script read file character 25 because date start , should regular checks see if there old files. current script looks this:

#!/bin/bash  rm *$(date -d "-1 day" +"%y%m%d")* 

the problem script if computer not , running couple of days not delete old files past date , not start on character 25. please help, thanks

for day in {1..7};     rm -f ????????????????????????$(date -d "-$day day" +"%y%m%d").log done 

this allow script not running week; can change range handle longer periods.

there 24 ? characters in wildcard, find date starting @ character 25.

the -f option keeps rm printing error message if no matching files found. warning: prevents asking confirmation if don't have write permission file.

the notation {start..end} expands sequence of numbers start end, {1..10} short 1 2 3 4 5 6 7 8 9 10. can use {char1..char2} sequence of characters, e.g. {a..d} short a b c d.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -