Javatpoint Logo
Javatpoint Logo

Linux date Command

Overview

In Linux, the date command is used for displaying the time and date of the system. Also, it is used for setting the time and date of the system. The date command by default shows the date within the time zone over which Linux/Unix operating system is constructed. We should the root (super) user to modify the time and date.

Syntax of the date command:

Options in the date command

The following are some important options in the date command:

1. date (no option): The date command shows the current time and date with no options including the year, the time zone name, the time isolated by colons, day of the month, abbreviated month name, and the abbreviated day name.

The command is as follows:

Output:

The output will be as follows:

Linux date Command

Note: Unix system is constructed in neutral daylight time.

2. -d or --date Option: This command shows the provided date string within the date format. But, it will not impact the actual time and date value of the system. Instead, it used the time and date given in the string form.

Syntax:

The command is as follows:

Output:

The output will be as follows:

Linux date Command

3. -u Option: It shows the time in UTC (Coordinated Universal Time)/GMT (Greenwich Mean Time) time zone.

The command is as follows:

Output:

The output will be as follows:

Linux date Command

4. --date option to show past dates

  • Time and date of 1 year ago.

The command is as follows:

Output:

The output will be as follows:

Linux date Command
  • Time and date of 4 seconds ago.

The command is as follows:

Output:

The output will be as follows:

Linux date Command
  • Time and date of the previous day.

The command is as follows:

Output:

The output will be as follows:

Linux date Command
  • Time and date of 1 month ago.

The command is as follows:

Output:

The output will be as follows:

Linux date Command
  • Time and date of 5 days ago.

The command is as follows:

Output:

The output will be as follows:

Linux date Command

5. --date option to show the future date

  • Time and date of the upcoming specific day of the week.

The command is as follows:

Output:

The output will be as follows:

Linux date Command
  • Time and date after 3 days.

The command is as follows:

Output:

The output will be as follows:

Linux date Command
  • Time and date of the next day.

The command is as follows:

Output:

The output will be as follows:

Linux date Command
  • Time and date of after 2 years on the day (current).

The command is as follows:

Output:

The output will be as follows:

Linux date Command

6. --set or -s Option: It is used for setting the time and date of the system.

Syntax:

Command:

Output:

The output will be as follows:

Command:

Output:

The output will be as follows:

7. -f or --file Option: It is used for displaying the date string available at all file lines in the time and date format. This option is the same as an option, i.e., --date. Although, a single difference between these options is that in --date option we can only provide a single date string but we can provide more than one date string at all the lines in a file.

Syntax:

The command is as follows:

Output:

The output will be as follows:

Linux date Command

8. -r Option: It is used for displaying the modified timestamp (last) of a datefile.

Syntax:


Linux date Command

Also, we can change the timestamp of any datefile by applying the touch command.

Syntax:


Linux date Command

9. Format specifier list used using the date command

Syntax:

Examples:

Some of the examples of the date command are as follows:

  • Command:

Output:

Linux date Command
  • Command:

Output:

Linux date Command
  • Command:

Output:

Linux date Command
  • Command:

Output:

Linux date Command
  • Command:

Output:

Linux date Command

Formatting Characters

There are the most widely used formatting characters of the date command:

%Y: Year (e.g., 2021)

%D: Show date as mm/dd/yy

%m: Month (02-14)

%B: Long month name (e.g., December)

%b: Shirt month name (e.g., Dec)

%d: Day of month (e.g., 02)

%j: Day of year (002-366)

%u: Day of week ((2-7)

%A: Full weekday name (e.g., Saturday)

%a: Short weekday name (e.g., Sat)

%H: Hour (00:24)

%I: Hour (02-12)

%S: Second (00-60)

%M: Minute (00-59)

Note: We can execute the man date (man command) or date --help in our terminal to see every formatting option.


Next TopicLinux hosts (file)





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA