Linux date command and linuxdate command

Source: Internet
Author: User

Linux date command and linuxdate command
Command Overview

The date command can be used to set and display the current time of the system. In particular, the date command is used in some Shell commands to display different dates. Therefore, this command is also a very important command.

 

Syntax

Date [OPTION]... [+ FORMAT]
Date [-u | -- utc | -- universal] [MMDDhhmm [[CC] YY] [. ss]

1. command parameters:

-D, -- date: display the date-f described by the string, -- file: display the time of each row in the DATEFILE-r, -- reference: display the last modification time of the file-R, -- rfc-2822: Output Date and Time-s in RFC2822 format, -- set: set Time-u, -- utc: output or set Coordinated Universal Time -- help: help information -- version Information

2. FORMAT

Used for display of different time formats

% H hour (00 .. 23) % I hour (01 .. 12) % k hour (0 .. 23) % l hour (1 .. 12) % M (00 .. 59) % p displays AM or PM % r time (hh: mm: ss AM or PM ), 12 hours % s the number of seconds that have elapsed since January 1, 1970 00:00:00% S (00 .. 59) % T time (in 24-hour format) (hh: mm: ss) % X display time format (% H: % M: % S) % Z Time Zone date domain % a abbreviation of the day of the week (Sun .. sat) % A full name of the day of the week (Sunday .. saturday) % B (Jan .. dec) % B FULL NAME (January .. december) % c date and time (Mon Nov 8 14:12:46 CST 1999) % d day of the month (01 .. 31) % D Date (mm/dd/yy) % h and % B options are the same % j day of the year (001 .. 366) % m month (01 .. 12) % w the day of the week (0 represents Sunday) % W the day of the year (00 .. 53, Monday is the first day) % x display Date Format (mm/dd/yy) % y the last two digits of the year (1999 is 99) % Y (for example: 1970,1996, etc.) % Y year % z + hhmm numeric timezone (e.g ., -0400) %: z + hh: mm numeric timezone (e.g ., -) %: z + hh: mm: ss numeric time zone (e.g ., -04:00:00) % ::: z numeric time zone with: to necessary precision (e.g ., -04, + 05:30) % Z alphabetic time zone abbreviation (e.g ., EDT)

3. Example

Current Time

# Display the current date and time

 

Display the time two days ago

# Display date-d "+ 2 days ago" two days ago"

Display the current time in % Y-% m-% d % H: % M: % S format

# Display the current time in the format of % Y-% m-% d % H: % M: % S + % Y-% m-% d % H: % M: % S"

Display time two days ago in % Y-% m-% d % H: % M: % S format

# Display the time two days ago and output it in % Y-% m-% d % H: % M: % S format
date -d "+2 days ago" "+%Y-%m-%d %H:%M:%S"

Other methods

# Two days later, date-d "-2 days ago" + % Y % m % d # One week ago date-d "1 week ago" + % Y % m % d # One date-d "-1 week ago" + % Y % m % d # date-d "1 month ago" + % Y % m % d
# One month later date-d "-1 month ago" + % Y % m % d
# One year ago date-d "1 year ago" + % Y % m % d # next day date-d next-day + % Y % m % d # previous day date-d last -day + % Y % m % d # the day before yesterday date-d yesterday + % Y % m % d # tomorrow date-d tomorrow + % Y % m % d # last month date-d last-month + % Y % m % d # next month date-d next-month + % Y % m % d # last year date-d last-year + % Y % m % d # next year date-d next-year + % Y % m % d

4. modify the system date and time

Modify the date only. Enter date-s

Modify the time only. Enter date-s 21:00:00.

Modify the date and time at the same time. Add double quotation marks. There is a space between the date and time. Enter:

Date-s "21:00:00"

After modification, write the system time to the CMOS and hardware clock to avoid invalidation after restart. Enter:

Clock-w

 

Summary

There are still a lot of tips for using the date command, which is not listed here. This command is often used in shell commands such as date files, so you need to be familiar with it.

 

 

 

Note:

Author: pursuer. chen

Blog: http://www.cnblogs.com/chenmh

All essays on this site are original. You are welcome to repost them. However, you must indicate the source of the article and clearly give the link at the beginning of the article.

Welcome to discussion

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.