ubuntu - Bash script: Use of date in foldername for calculation (Delete folders older than X) -


we have backup foldernames "db_yyyy-mm-dd".

is there kind of command/expression use compare folder's (name-)date current (system-)date , delete older x days?

background: tried "find" , "-mtime +x" modification time not perfect solution because updates when modify/delete files inside folders afterwards..

it rare condition makes -mtime comparison "faulty", alternative , the folder's name doesn't change ever during creation/backup/modification..

you can use following way generate folder name

#foldername="db_"`date "+%y-%m-%d"` #echo $foldername db_2017-08-15 #mkdir $foldername 

now can compare string given date

so 7 days older date be

 givendate="db_"`date -v-7d "+%y-%m-%d"` 

if ($foldername > $givendate)

 true if foldername sorts after givendate lexicographically. 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -