Record the time of Shell cancellation each time

Source: Internet
Author: User
Tags iso 8601 iso 8601 format

A friend wants to log out of shell every time a few days ago. He can add the following command to the. bash_logout file:

date -d today +"%Y-%m-%d %H:%M:%S" >> /var/log/logout

The test is as follows:

Open two windows, one of which is to view the current time, and the other exit to exit the shell. Check that the second line of the generated/var/log/logout file is the time I exited.

The time output commands in other formats are as follows:

# Date-d today + "% Y-% m-% d"
2013-02-07
# Date-d today + "% Y _ %-m _ %-d"
2013_2_7
# Date-d today + "% Y-% m-% d % T"
2013-02-07 22:42:24
# Date-d today + "% Y-% m-% d % H: % M"

# Date-d today + "% Y-% m-% d % H: % M: % S"
2013-02-07 22:42:35

The detailed usage of the date command is as follows:

Date Command Parameters

  • -D,-date = STRING: display the time specified by STRING

  • -F,-file = DATEFILE, similar to the-date parameter, shows the time of each row in the DATEFILE file.

  • -ITIMESPEC,-iso-8601 [= TIMESPEC] displays date/time in ISO 8601 format. TIMESPEC is one of the following values: "date" (only display date), "hours", "minutes", and "senconds" (display time precision). The default value is "date ".

  • -R,-reference = FILE: displays the last modification time of the FILE.

  • -R,-the rfc-2822 displays time in RFC-2822 compatible Date Format

  • -S,-set = STRING is set to STRING

  • -U,-utc,-universal Display or set to Coordinated Universal Time Format

Date command output display format

  • % Characters %

  • % A abbreviation of a week (Sun .. Sat)

  • % A full name of the Week (Sunday .. Saturday)

  • % B (Jan .. Dec)

  • % B full name of the month (January... December)

  • % C date and time (Sat Nov 04 12:02:33 EST 1989)

  • % C Century (excluding the sum after 100) [00-99]

  • % D the day of the month (01 .. 31)

  • % D Date (mm/dd/yy)

  • % E the day of a month (1 .. 31)

  • % F date, same as % Y-% m-% d

  • % G year (yy)

  • % G year (yyyy)

  • % H is the same as % B

  • % H hour (00 .. 23)

  • % I hour (01 .. 12)

  • % J the day of the year (001 .. 366)

  • % K hour (0 .. 23)

  • % L hour (1 .. 12)

  • % M month (01 .. 12)

  • % M minutes (00 .. 59)

  • % N line feed

  • % N nanoseconds (000000000 .. 999999999)

  • % P AM or PM

  • % P am or pm

  • % R 12-hour time (hh: mm: ss [AP] M)

  • % R 24-hour system time (hh: mm)

  • % S seconds starting from 00:00:00 UTC

  • % S seconds (00 .. 60)

  • % T Tab

  • % T in 24-hour format (hh: mm: ss)

  • % U day of the week (1 .. 7); 1 indicates Monday

  • % U the week of the year, and Sunday is the first day of the week (00 .. 53)

  • % V the week of the year. Monday is the first day of the week (01 .. 53)

  • % W the day of the week (0 .. 6); 0 indicates Sunday

  • % W the week of the year, and Monday is the first day of the week (00 .. 53)

  • % X date (mm/dd/yy)

  • % X time (% H: % M: % S)

  • % Y year (00 .. 99)

  • % Y year (1970 ...)

  • % Z RFC-2822 style numeric format Time Zone (-0500)

  • % Z Time Zone (e.g., EDT). If the time zone cannot be determined, it is null.


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.