cleanup script to put files into date folders

Preface

I made a backup-script which just dumps it’s files into 1 folder, but that got messy pretty quickly. I needed a script which could cleanup files (*.tgz) from a folder and put them into their respective date-folder.

Code

#!/bin/bash
cd /rootfolder/to/cleanup
for x in *.tgz; do
d=$(date -r "$x" +%Y-%m-%d)
mkdir -p "$d"
mv -- "$x" "$d/"
done

Leave a Reply

Your email address will not be published. Required fields are marked *