Artificial intelligent assistant

BASH - Simple script with rm command doesn't work I have made this simple script: #/bin/bash DATE=$(date +"%d_%m_%Y-%H:%M:%S") tar -czvf /kopie/bin-$DATE.tar /bin DATE=$(date --date="2 hours ago" +"%d-%m-%Y_%H") rm -f /kopie/bin-$DATE*.tar I have problem with the last line of the script. rm command doesn't work, it doesn't delete file. The "2 hours ago" date works great, so it's not problem with this.

You seem to specify the file name in two different ways:


DATE=$(date --date="2 hours ago" +"%d-%m-%Y_%H")


Above, there is e.g. a _ between year and hour.

But the date you generated had a different format:


DATE=$(date +"%d_%m_%Y-%H:%M:%S")


However this still would not solve the inherent problem of getting "a date **more or less** two hours ago", because it takes a single second to go from 13:00:00 to 12:59:59, which does not match a "2017-11-20_13*" pattern anyway.

I'd look into using `find`:


find . -name "*.tar" -maxdepth 0 -cmin +120 -delete


should kill all *.tar files in the current directory older than two hours (use +119 to have a one minute grace time). Also, you can omit `-delete` when testing whether this approach works.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 2734f19a92aa18608af3683f3df458a1