Bash date print X days ago (Linux shell script or in command-line)

How to print X days ago date in bash

This is particularly useful when you are looking for the date of a specific number of days ago, regardless of week or month.

Example #1: To print the date that is 10 days ago:

date --date="10 days ago"

Example #2: To print the date that is 30 days ago:

date --date="30 days ago"

Example #3: To print the date that is 5 days ago:

date --date="5 days ago"

When you copy-paste, if there are any error messages, please try typing the above commands manually (instead of copying – just type them)

This will work on any bash shell (Ubuntu, Linux, Docker containers, etc)

FAQs

We this, these pages are related, please check…

How to print the day before yesterday’s date in a bash shell script?

How to print X Days after in a shell script?

Bash date print date including milliseconds.

Bash, the shortest way to echo the full date