Urgent.News

What's breaking now, across thousands of outlets.

Tech

date -d "-1 month" Named the Current Month on Seven Days of 2026: Picking Last Month's Camera Clip Folder in Bash

A monthly job for a phone camera packs up last month's clip folder, clips/2026-02 say, and frees the space. The usual way to get that folder name in a shell script is date -d -1month +%Y-%m , or the same thing spelled with a space inside quotes. I ran that line against every day of 2026. On seven days it names the current month, which is the folder the camera is still writing to. The test The…

A bash script tests three methods for naming the previous month's folder in the context of a phone camera job. The script runs on each day of 2026, comparing the output of each method against the real previous month. It finds that the simple "date -d -1month" method is accurate on 358 days of the year, while the other two methods ("1 month ago" and "last month") fail on 7 days.

The failures occur due to the script keeping the day of the month, changing the month number, and then normalizing the result. This causes issues when the previous month does not have enough days (e.g., March 31st points to March). The script also tests this issue for the upcoming year, finding similar problems with the "+1 month" method skipping February.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Saturday 14 November →