
For a list of BASHing data 2 blog posts see the index page.
Rename time-series files for chronological sorting
What I call "time-series files" are documents like monthly financial statements, monthly newsletters and quarterly reports. I don't modify them after I receive them, and they get filed and archived in an appropriate folder, like "[Organisation name]-newletters".
Often the time-series file doesn't have an informative name. My last quarterly water bill from TasWater, for example, arrived as "document15176075861143268989.pdf" (I am not making this up). Even when the filename is informative, the date component might be less than obvious: "Smalltown Tennis Club Dec 24 news.pdf".
I've recently gotten into the habit of renaming time-series files to make them chronologically sortable by filename, as in "2024-12-18-TasWater-bill". I wanted to do the same for the contents of folders-ful of legacy documents, so I turned to the command line and date -r, which returns the last-modified date of a file or folder.
After I navigated to the folder-ful of time-series files (related, non-time-series files are in other folders), my command looked like this:
for i in *; do mv "$i" "$(date -r $i +"%Y-%m-%d")-[text for the nature of the file]; done
Below I show before-and-after file listings for a folder with monthly statements from one of our telecom providers.

The toptail function toptail() { sed -u '10q'; echo "---"; tail; } returns the first and last 10 items in a list.
Note the lack of a filename extension (".pdf"). Since these are my own personal time-series files, used and archived on Linux machines, a filename extension is just digital noise. My file managers, browsers and document apps can all read the first line of the file header, which is "%PDF-1.4", and will act accordingly.
Next post:
2025-04-11 A launcher for occasionally used applications
Last update: 2025-04-04
The blog posts on this website are licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License