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 is an error message, please try typing the above manually (instead of copy – just type them)

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