To print date in terminal default format
[root@localhost]# date
Sun Mar 25 16:21:21 IST 2012
To print Date in terminal GMT/UTC time zone
[root@localhost]# date -u
Sun Mar 25 10:51:25 UTC 2012
To print Date in terminal RFC format
[root@localhost]# date -R
Sun, 25 Mar 2012 16:21:34 +0530
For setting date
Using User friendly format "01/01/2000 12:12:12" and -s option
[root@localhost]# date
Sun Mar 25 16:24:09 IST 2012
[root@localhost]# date -s "01/01/2000 12:12:12"
Sat Jan 1 12:12:12 IST 2000
[root@localhost]# date
Sat Jan 1 12:12:13 IST 2000
Using précised format 0701040095
[root@localhost]# date
Fri Jan 21 12:20:46 IST 2000
[root@localhost]# date 0701040095
Sat Jul 1 04:00:00 IST 1995
[root@localhost]# date
Sat Jul 1 04:00:02 IST 1995
Where date is set as,
July 1 -> 0701
4 a.m. -> 0400
2005 -> 05
To display Month, Day and Year
[root@localhost]#
date '+%m-%d-%Y'
01-01-2000
where,
%m -> to
get the month value
%d -> to
get the value of day of the month
%Y -> to
get the value of Year
To display Hours, Minutes and Seconds
[root@localhost]#
date '+%H-%M-%S'
12-16-11
Where,
%H -> to
get the Hours value
%M -> to
get the value of Minutes of the Hour
%S -> to
get the value of Seconds of the Minute
To display Month, Day, Year, Hours, Minutes and Seconds
[root@localhost]#
date '+%m-%d-%Y %H-%M-%S'
01-01-2000
12-16-16
To find the number of seconds from UNIX epoch.
[root@localhost]#
date '+%s'
946709313
Where,
%s -> to
get the date and time in unix epoc format which is a system for describing
instants in time, defined as the number of seconds elapsed since midnight
Coordinated Universal Time (UTC) of Thursday, January 1, 1970
This is the reference http://en.wikipedia.org/wiki/Unix_time
To get Date in single parameter
[root@localhost]#
date +"%D"
01/01/00
Where
%D -> to
get the date in MM/DD/YY format
[root@localhost]#
date +"%T"
12:32:59
Where,
%T -> to
get the date in HH:MM:SS format
To display date with customized text
[root@localhost]#
date +"Hello%t Date is %D %n%t Time is %T"
Hello
Date is 01/01/00
Time is 12:27:33
Where,
%n ->
newline character to add newline in output
No comments:
Post a Comment