Linux Commands: How to Display Yesterday’s Date (and more)
The “date” command on Linux is not a hard one to remember, but mastering its use with the various options and formats available can be a challenge. I’ll show you how to easily print yesterday’s date and give you a few tips to get exactly what you need.
The easiest way to print yesterday’s date using a Linux command is to use the “-d” or “–date” option, specifying the string “yesterday”:date -d "yesterday"
Let’s get into it right away with a more detailed answer and a few examples you need to know.
If you need help with Linux, I’ve got something that can help you right away!
Download my free Linux commands cheat sheet – it’s a quick reference guide with all the essential commands you’ll need to get things done on your system. Click here to get it for free!
Getting yesterday’s date using Linux commands
On Linux, the “date” command has an option to specify the date to display in a human format. For example, we can use “yesterday” or “now” to get a different result.
The option to print a specific date is “–date”, which can be shortened to “-d”. It looks like this for yesterday’s date:date --date=yesterday
date -d yesterday
If you try it on your system, you’ll see that you get the date from yesterday at the same time, not the current date. You can then combine it with the other options of the date command, for example, to get the date in a specific format:date -d yesterday +"%Y-%m-%d"
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.
Download now

You now have your short answer about how to quickly get yesterday’s date on Linux. But I’ll now explain these two parameters in more detail so you can also use them in other situations.
Linux date command: the -d option explained
The “-d” or “–date” option with the Linux “date” command displays the time described in the parameter, not the current date and time.
Let’s see how to use this option.
How to get tomorrow’s date in the Linux terminal?
To get tomorrow’s date in the Linux terminal, you can also use -d in the same way:date -d tomorrow
date -d tomorrow +"%Y-%m-%d"
Members get an ad-free version of every guide, plus exclusive project support.
Join the Community | Sign In
The “-d” option is a smart option that will recognize what you specify in the parameter, even if it’s written in human format.
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.
Download now
Tip: Command lines can be a pain to memorize. I put the essential Linux commands on a printable cheat sheet so you don't have to keep googling them. You can grab the PDF here if you want to save some time.
How to get any specific date in the Linux terminal
The –date parameter of the date command on Linux (or -d for short) accepts a wide range of string formats to represent dates and times.

Here’s a list of some possible options:
- Specific date:
date -d yesterday
date -d now
date -d tomorrow - Relative dates:
date -d "2 days ago"
date -d "3 weeks ago"
date -d "last year"
date -d "next thursday"
date -d "8 days later" - Time-based:
date -d "13:00 tomorrow"
date -d "8am yesterday"
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.
Download now
As you can see, you can easily get any date using this option, by just describing it in plain English. Remember to add quotes around your query when it’s longer than one word though. It will avoid interpretation issues. The -d parameter needs to be one string, not more.
I have worked with various programming languages and I can tell you that most don’t have an option as easy to use as this one. Enjoy, especially if you write scripts using it ;-).
Want to connect with other Raspberry Pi fans? Join the RaspberryTips Community. Ask questions, share your projects, and learn from each other. Join now.
Formatting dates in the Linux terminal
Now that you know how to get a specific date in a Linux terminal, you might need some additional guidance to format it properly. The default format is pretty long, and largely useless in most cases, especially if you aim to use this date in scripts.
Date formatting essentials
By default, the “date” command prints the date with all the details (in ctime format), including day, month, time, timezone and year.
The default syntax looks like this:Day Mon DD HH:MM:SS Timezone YYYYFor example:Wed Aug 24 14:30:00 UTC 2023
But you can change the format to anything you want by specifying it after the “+” symbol at the end of your command line:date +"<FORMAT>"
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.
Download now
The format is described using sequences like:
- %Y: Year (2023)
- %m: Month (01-12)
- %d: Day (01-31)
- %A: Full weekday (Sunday)
%a: Short weekday (Sun) - %B: Full month name (August)
%b: Short month name (Aug)
All the other characters in your format string will not be interpreted, so you can use “-“, “,” or “/” to separate values.
Examples
The easiest way to understand how this format parameter works is to give you some examples:

- As mentioned earlier, the “date” command, without any format specified, prints a long string with all the details (first line).
- If you add this to the command: +”%Y-%m”, you’ll get only the current year and month, separated with a dash:
date +"%Y-%m" - In the next example, we add the weekday and remove the month by using a different format:
date +"%A %d, %Y"You probably won’t use this format, but it’s just to understand how it works. - The last command prints the date in a typical European format (day/month/year):
date +"%d/%m/%Y"
Remember to check the manual for more details and format options not listed here:man date
And if you want to expand your skills with Linux commands, you should also check my other articles on the topic:
- 50 Most Useful Linux Commands You Need To Know (Cheat Sheet)
- How to Increase Font Size in the Linux Terminal (+ Bonus tips)
- 3 Best Ways to Access a Website in a Linux Terminal
Whenever you're ready, here are other ways I can help you:
Master Linux Commands: Overwhelmed with Linux commands? This book is your essential guide to mastering the terminal. It includes practical tips, real-world examples, and a bonus cheat sheet to keep by your side.
The RaspberryTips Community: Need help with Linux or want to chat with people who actually get it? Join the RaspberryTips Community and get access to private forums, exclusive lessons, and direct support.
You can also find all my recommendations for tools and hardware on this page.
