AI Hints
Home›Linux Tutorial›Archives
Linux · Lesson 90 of 120

Practice: A Dated Backup

Tar plus date.

⏱ 2 min read▶ Video at 2:00:19🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

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.

Practice: A Dated Backup
From the video: Practice: A Dated Backup
  • 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.

Terminal
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.

Terminal
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.

keyvalue
date +%Y-%m-%dtoday's date
$(command)use its output
tar -czfcompressed archive
Coming soonrun 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
Next up: Networking Basics — IP addresses and names