I Alias This One-Liner to 'mktoday' and Use It Every Single Week

I Alias This One-Liner to 'mktoday' and Use It Every Single Week

Leader posted 2 min read

My project folder used to look like this:

new-site/
new-site-2/
new-site-final/
new-site-final-ACTUAL/
test-backup/
backup-old/

Yours probably looks similar. We've all been there. You start a project, name the folder something reasonable, and then six months later there are four variations of it and you have no idea which one is current.

The fix is embarrassingly simple: put the date in the folder name when you create it.


The Command

mkdir "$(date +%Y-%m-%d)_project-name"

That creates: 2026-05-22_project-name

That's it. One command. But the trick is making it effortless enough that you actually use it every time.


Make It an Alias

Open your .bashrc (or .zshrc if you're on macOS/zsh):

nano ~/.bashrc

Add this line at the bottom:

alias mktoday='mkdir "$(date +%Y-%m-%d)_${1:-project}"'

Save, then reload:

source ~/.bashrc

Now you can type:

mktoday client-redesign

And get: 2026-05-22_client-redesign

No thinking. No formatting. No "was it DD-MM or MM-DD?" The alias handles it.


Why YYYY-MM-DD and Not Anything Else

This isn't a style preference. It's a sorting issue.

If you use MM-DD-YYYY (the American date format), your folders sort like this:

01-15-2026_project/
02-03-2025_project/
03-22-2026_project/
12-01-2024_project/

That's sorted by month, not by date. January 2026 comes before February 2025. Useless.

With YYYY-MM-DD (ISO 8601), they sort correctly:

2024-12-01_project/
2025-02-03_project/
2026-01-15_project/
2026-03-22_project/

Chronological order. In every file manager. In every ls output. On every operating system. This is why ISO 8601 exists.


The Script Version (With Backup Built In)

If you want the folder creation to also copy files into it — like a timestamped backup — here's the expanded version:

#!/bin/bash
SOURCE="/home/user/documents"
BACKUP_ROOT="/backup"
DATE=$(date +%Y-%m-%d_%H-%M)
DEST="$BACKUP_ROOT/$DATE"

mkdir -p "$DEST"
cp -r "$SOURCE" "$DEST"
echo "✓ Backed up to: $DEST"

This is the same concept but applied to automation. Create a dated folder, copy files into it, done. Schedule it with cron and you've got timestamped versioned backups.


The date Format Codes You'll Actually Use

You don't need to memorize all of them. Here are the ones that matter:

%Y — 4-digit year (2026)
%m — 2-digit month (05)
%d — 2-digit day (22)
%H — Hour in 24h format (14)
%M — Minutes (30)
%b — Abbreviated month name (May)

So date +%Y-%m-%d gives you 2026-05-22 and date +%Y-%m-%d_%H-%M gives you 2026-05-22_14-30 if you need time precision too.


Common Mistakes

Forgetting quotes around the folder name. If your project name has spaces, mkdir $(date +%Y-%m-%d)_my project creates two things: a folder called 2026-05-22_my and whatever bash makes of the word project on its own. Always wrap it: mkdir "$(date +%Y-%m-%d)_my project".

The alias not surviving a reboot. Adding alias mktoday=... in the terminal works for that session only. You have to put it in ~/.bashrc AND run source ~/.bashrc for it to stick.


This is one of those things that takes 30 seconds to set up and quietly makes your life better every week. Full walkthrough, more format examples, and the backup version:

bashsnippets.xyz/snippets/create-dated-folder.html

Part 4 of 4 in Bash Snippets Pages

More Posts

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelskiverified - Mar 19

TypeScript Complexity Has Finally Reached the Point of Total Absurdity

Karol Modelskiverified - Apr 23

My Nginx Died at 2 AM and Nobody Noticed for 6 Hours. Now I Have a Watchdog Script

BashSnippets - May 21

I Wrote a Script to Fix Audible's Unreadable PDF Filenames

snapsynapseverified - Apr 20

Just completed another large-scale WordPress migration — and the client left this

saqib_devmorph - Apr 7
chevron_left

Related Jobs

View all jobs →

Commenters (This Week)

1 comment
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!