Practice: A Dated Backup
Tar plus date.
Here's a practical task. Back up your Documents folder into a compressed archive, with today's date in the file name, so you can keep a backup for every day. Pause and try it.

- Back up Documents
- Compressed
- With today's date in the name
The date in a file name
Date can print in any format you like. Plus, percent capital Y, dash, percent M, dash, percent D, gives year, month, and day. Dollar, then brackets around a command, called command substitution, puts the command's output right into another command. Like this.
date +%Y-%m-%d 2026-01-05 echo "backup-$(date +%Y-%m-%d).tar.gz" backup-2026-01-05.tar.gz
The backup
Now the real thing. Tar dash CZF, with the dated name, and the Documents folder. LS shows the backup, with today's date. Run the same command tomorrow, and you'll get a second file, without replacing the first.
tar -czf "backup-$(date +%Y-%m-%d).tar.gz" Documents ls -l backup-* -rw-r--r-- 1 sam sam 266 Jan 5 09:00 backup-2026-01-05.tar.gz
Making it automatic
A backup you have to remember is a backup you'll forget. Later in this course, we'll put this command in a script, and tell Linux to run it every night by itself. That's where all these pieces come together.
| key | value |
|---|---|
| date +%Y-%m-%d | today's date |
| $(command) | use its output |
| tar -czf | compressed archive |
| Coming soon | run it every night |
Summary
You made a dated, compressed backup, using tar, date, and command substitution. Next, a new section. Networking, and connecting to other computers.
Key takeaways- date +%Y-%m-%d
- $(...)
- tar -czf backup-date.tar.gz