_ _ (_) ___ | |_ ____ | |/ _ \| __|_ / | | (_) | |_ / / _/ |\___/ \__/___| |__/
This is a Bash script I wrote to rename a set of markdown files I had backed up from the old version of Jotz CMS that was used to host my tedz.eu website. The original name of each file was the article title followed by ".md". The new name of each file is the same format currently used by Jotz CMS to store the markdown of each article, basically a human-readable timestamp in this format: "yyyymmdd-hhmmss.md". The Bash script also inserts a pandoc-style metadata block to the beginning of each file with the article title (taken from the original filename).
#!/bin/bash
#for f in ./*
for f in *
do
if [[ "$f" == *\.md ]]
then
newfilename=$(date -r "$f" +%Y%m%d_%H%M%S.md)
title=${f:0:-3}
output_file=$newfilename
echo --- > $output_file
echo "title: $title" >> $output_file
echo ... >> $output_file
echo "" >> $output_file
cat "$f" >> $output_file
echo $newfilename
fi
done