Skip to content

Create a Dated Folder

filesdatemkdir
5 min read

Quick Answer

The date +%Y-%m-%d command outputs the current date in ISO 8601 format — for example 2026-06-03. Using this as a folder name means directories sort in chronological order automatically when you run ls, since lexicographic order matches date order for YYYY-MM-DD. The two-command workflow is: DATE=$(date +%Y-%m-%d) to capture the date string, then mkdir "$DATE" to create the folder. In a backup context, this creates a new unique folder every day without overwriting previous backups. Adding the hour and minute with date +%Y-%m-%d_%H-%M creates folders like 2026-06-03_14-30 for multiple runs per day. Wrap both commands in a cron job to auto-create a fresh folder at the start of each backup run. date and mkdir are coreutils built-ins present on every Linux distribution and macOS out of the box — no packages required.

Past-me had a naming convention for backups, if it deserves the word: a folder called backup, beside backup2, beside backupNEW, beside backup_final, all piled onto the same 2 TB drive over months of "I'll make a quick copy first." The day I actually needed one of them, I opened the drive and genuinely could not tell which was the good one. Same names, near-identical sizes, and every manual copy I'd ever made had been quietly clobbering or shadowing the one before it. The copy I wanted was probably in there. It was also probably the one I'd overwritten.

The failure here is almost embarrassingly basic: a name with no date in it carries no information about when it was made or whether it's current, so every "quick copy" competes with the last instead of joining a timeline. Stamp the date into the name in YYYY-MM-DD order and the problem evaporates — the folders sort themselves chronologically in ls, nothing collides, and "which one is newest" becomes something you can see instead of guess. The one-liner below is what I should have been typing from the start, and the alias further down is how I made it the path of least resistance — the part I wasn't willing to keep getting wrong.

The One-Liner

Run this directly in your terminal — no script file needed.

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

What this creates

Running this today creates a folder called 2026-05-03_project. The $() syntax runs the date command and drops the result directly into the folder name. The +%Y-%m-%d format gives you year-month-day — which sorts correctly in every file manager.

From one-liner to daily habit

Step 1 — Run the one-liner directly in your terminal

No script file required. Open any terminal and run:

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

Replace _project with any label you want — _backup, _deployment, _client-meeting. The date prefix is added automatically.

Step 2 — Verify the folder was created

bash
ls -d $(date +%Y-%m-%d)*

You should see the new folder listed. It sorts immediately to the correct chronological position alongside any other dated folders in the same directory.

Step 3 — Use the script version for repeat runs

When you need dated folders regularly (daily backups, weekly deploys, client deliverables), save the script version so you can add a custom label each time:

bash
nano mkdate.sh

Paste the script variation from the Variations section below. Save with Ctrl+X → Y → Enter, then make it executable:

bash
chmod +x mkdate.sh

Run it with any label:

bash
./mkdate.sh deployment # Creates: 2026-06-03_deployment ./mkdate.sh client-report # Creates: 2026-06-03_client-report

Step 4 — Add it as a permanent alias

This is what turns a one-liner into a daily habit. Add the alias to your shell config:

bash
nano ~/.bashrc

Paste at the bottom:

bash
alias mkdate='mkdir "$(date +%Y-%m-%d)_folder" && cd "$(date +%Y-%m-%d)_folder"'

Save, then activate immediately without reopening the terminal:

bash
source ~/.bashrc

Now type mkdate from anywhere to create and enter a new dated folder in seconds.

Using zsh?

Add the alias to ~/.zshrc instead, then run source ~/.zshrc. The alias syntax is identical — only the file changes.

Date Format Options

date +%Y-%m-%d 2026-05-03 Best for general use — sorts correctly

date +%Y-%m-%d_%H-%M 2026-05-03_14-32 Includes time — good for multiple per day

date +%Y%m%d 20260503 Compact — good for short names

date +%b-%d-%Y May-03-2026 Human readable — does not sort well

Other ways I name dated folders

Create and immediately cd into it

bash
DIR="$(date +%Y-%m-%d)_project" mkdir "$DIR" && cd "$DIR"

Create with a custom name after the date

bash
mkdir "$(date +%Y-%m-%d)_client-meeting" mkdir "$(date +%Y-%m-%d)_deployment" mkdir "$(date +%Y-%m-%d)_backup"

Create a dated folder inside a target directory

bash
mkdir -p ~/projects/"$(date +%Y-%m-%d)_new-feature"

The -p flag creates any missing parent directories. If ~/projects/ doesn't exist yet, it gets created automatically.

Script version — reusable with a custom name argument

bash
#!/bin/bash # Create a dated folder with an optional name # USAGE: ./mkdate.sh [optional-name] # EXAMPLE: ./mkdate.sh deployment → creates 2026-05-03_deployment DATE=$(date +%Y-%m-%d) NAME="${1:-folder}" # ← uses "folder" if no argument given FULL="${DATE}_${NAME}" mkdir -p "$FULL" echo "✓ Created: $FULL" cd "$FULL"

Add it as an alias

Add this to your ~/.bashrc to create dated folders from anywhere with one command:

alias mkdate='mkdir "$(date +%Y-%m-%d)_project" && cd "$(date +%Y-%m-%d)_project"'

Then run source ~/.bashrc and type mkdate whenever you need a new timestamped working folder.

Organize daily backups automatically

Combine dated folders with your backup script to organize every backup into its own timestamped directory:

bash
#!/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"

Understanding the date Command

Format codeWhat it producesExample
%Y4-digit year2026
%m2-digit month (01–12)05
%d2-digit day (01–31)03
%HHour in 24h format (00–23)14
%MMinutes (00–59)32
%SSeconds (00–59)07
%bAbbreviated month nameMay
%AFull weekday nameSunday

Always quote your folder names

Always wrap dated folder names in quotes: mkdir "$(date +%Y-%m-%d)_my project". Without quotes, spaces in the name break the command into multiple arguments. The "$()" pattern handles this correctly.

Where dated folders go wrong

Spaces in folder names break without quotes

mkdir $(date +%Y-%m-%d)_my project creates TWO items: a folder and a broken argument. Always wrap in double quotes: mkdir "$(date +%Y-%m-%d)_my project"

Date format that doesn't sort correctly

Using MM-DD-YYYY (like 05-13-2026) means folders sort by month, not chronologically. Always use YYYY-MM-DD (ISO 8601) — it sorts correctly in every file manager and ls output.

The alias doesn't persist after reboot

Adding an alias in the terminal only lasts for that session. You must add it to ~/.bashrc (or ~/.zshrc) AND run source ~/.bashrc for it to survive a reboot.

Frequently Asked Questions

How do I create a folder with today's date in bash?

Run: mkdir "$(date +%Y-%m-%d)_project" — this creates a folder like 2026-05-03_project. The $(date +%Y-%m-%d) part runs the date command and inserts the result directly into the folder name.

How do I add a timestamp to a folder name in Linux?

Use date +%Y-%m-%d_%H-%M inside $(): mkdir "folder_$(date +%Y-%m-%d_%H-%M)". This gives you both the date and time in the name, useful when creating multiple folders on the same day.

What date format is best for folder names?

Use ISO 8601 format: YYYY-MM-DD. This sorts correctly in every file manager because the most significant unit (year) comes first. Formats like MM-DD-YYYY sort incorrectly by month rather than year.

BashSnippets logo

Written by Anguishe

Creator of BashSnippets.xyz

bashsnippets.xyz/about

Run this script on a real Linux server

Get $200 free credit — DigitalOcean

Get $200 Free →

Affiliate link · we earn a commission

Need a domain for your next project?

Register with Namecheap — free WHOIS privacy included

Check Domain Prices →

Affiliate link · we earn a commission

PAID RESOURCE — $9

The Production Bash Toolkit

6 scripts + shared library + 52-page field guide. The production layer the free snippets don't cover.

Get the Toolkit →

Related Snippets

Frequently Asked Questions

faq — snippet

How do I run this script?

Run DATE=$(date +%Y-%m-%d) && mkdir "$DATE" directly in terminal, or save the script version and chmod +x it.

faq — snippet

Does this work on macOS?

Yes. date and mkdir are pre-installed on macOS with identical syntax for +%Y-%m-%d format.

faq — snippet

How do I create a folder with today's date in bash?

Run mkdir "$(date +%Y-%m-%d)" to create a folder named like 2026-06-03 in the current directory.

faq — snippet

What date format is best for folder names?

YYYY-MM-DD (ISO 8601) sorts chronologically in ls output. Add _%H-%M for multiple runs per day.