• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

date Command Examples in Linux

by admin

The date command is used to print the date in a specified format. The date command will print the date based on the /etc/localtime file. By default, it will print the date in the following format:

[day of week] [month] [day] [24 hour time ##:##:##] [time zone] [year]
Wed Oct 31 15:03:16 GMT 2018

You can also format the time using a number of different formatting options. You initialize the formatting options with a plus sign (+), and each option is prefaced with a percent sign (%). For example, to retrieve the week number (out of 52 weeks a year), you’d enter date +%V

You can also use the date command to change the system’s date by including the -s option with a provided argument.

Syntax

The syntax of the date command is:

# date [options] [format]

Formatting Options

The following table lists some of the formatting options available.

Formatting Option Prints
%A The full weekday name.
%B The full month name.
%F The date in YYYY-MM-DD format.
%H The hour in 24-hour format.
%I The hour in 12-hour format.
%j The day of the year.
%S Seconds.
%V The week of the year.
%x The date representation based on the locale.
%X The time representation based on the locale.
%Y The year.

date Command Examples

1, To display the date and time:

# date

2. To display the date and time entered by time:

# date --date=hh:mm:dd:mm:yy

3. To print the date from formats specified in each line of file:

# date -f file.txt
# date --file file.txt

4. To get the last modification time for a file:

# date file.txt

5. To output date and time in RFC 2822 format:

# date -R
# date --rfc-2822

6. To output date and time in RFC 3339 format:

# date --rfc-3339

7. To set the time specified by the time:

# date -u
# date --utc
# date --universal

8. To display the version information:

# date --version

Filed Under: Linux

Some more articles you might also be interested in …

  1. RHEL / CentOS : How to shrink LVM volume
  2. How to Delete unnecessary Entry in /etc/shadow
  3. How to extract RAR files in CentOS/RHEL 7 and 8
  4. restorecon Command Examples in Linux
  5. Sample /etc/services file in Linux
  6. CentOS / RHEL 6 : How to disable IPv6
  7. jpegoptim for image optimization
  8. How to Control user access to Virtual Machine in RedHat Virtualization
  9. How to run rsyslog as a non-root user in CentOS/RHEL 7
  10. How to Reserve a Port Range for a Third Party Application in CentOS/RHEL

You May Also Like

Primary Sidebar

Recent Posts

  • JavaFX ComboBox: Set a value to the combo box
  • Nginx load balancing
  • nginx 504 gateway time-out
  • Images preview with ngx_http_image_filter_module

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright