In this tutorial we will show you how to Use the unix date command. This command allows you to view the date in different formats. Furthermore, from the unix date commands you can view the current date, the previous dates and even the future dates.
To understand how to use the Date command, follow the tutorial steps given below.
Step 1 – Type in “date”
If you simply type “date” and hit enter, the current date and time of your machine will be displayed.
Step 2 – Break the date in three parts
For that we will break the date into three parts. The day, the month and the year. So we will use the percentage sign, which is a format specified and write d for the day. This will be followed by a backslash which is a separator. After that, we will input the forward slash sign, which will be used to differentiate between the day, the month and the year in the output.
The same pattern is followed for the month and the year over here.
Step 3 – Separate the date with dashes
If you want to separate the components of the date with dashes, you can simply input the dash sign after the separator over here.
Step 4 – View past and future dates
You can also view the past and future dates by using different unix date commands.
For example, to view the exact date 7 days ago, the command would be
date –d “-7 days”
Step 5 – View the 7th day from today
Similarly To view the date of the 7th day from today’s date, we will remove the dash sign before the number of days specified in the command.
And that it, from the above steps you can easily learn how to use the unix date command in Linux.