≡ Menu

date command

HowTo: Get Current Time In Shell Script

How do I get the current server time in shell script on Linux or Unix-like operating systems? How do I store the current time in the shell variable and use in my scripts?
[click to continue…]

Sysadmin because even developers need heroes!!!

UNIX Date Command Examples

How do I view and set date under UNIX operating systems? How do I see the current time/date on Unix based server?
[click to continue…]

Display Date And Time In Linux

How do I display date and time in Linux using command line and GUI options?
[click to continue…]

Find and Delete File If It Is More Than One Hour Old in UNIX Shell

Q. How do I find out file last modification time using a shell script or command? How do I delete or take any other custom action for all files more than one hour old in /home/ftp/incoming/raw/ directory?
[click to continue…]

OpenBSD Set Date and Time

Q. How do I set new date and time under OpenBSD UNIX server?
[click to continue…]

Linux / UNIX: displays a calendar and the date of easter with cal command

Q. date command displays date and time under a shell? How do I display calendar under Linux or UNIX?

A. date displays the Linux or UNIX system current date and time. The cal command displays a simple calendar in traditional format and ncal offers an alternative layout, more options and the date of easter. The new format is a little cramped but it makes a year fit on a 25×80 terminal. If arguments are not specified, the current month is displayed.

cal command

Just enter cal command as follows:
$ cal
Output:

    August 2007     
Su Mo Tu We Th Fr Sa
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

ncal command

ncal command changes the output format:
$ ncal
Output:

    August 2007
Mo     6 13 20 27   
Tu     7 14 21 28   
We  1  8 15 22 29   
Th  2  9 16 23 30   
Fr  3 10 17 24 31   
Sa  4 11 18 25      
Su  5 12 19 26   

Print calendar for year 2008

$ cal 2008
Output:

                               2008                                

       January               February                 March        
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
       1  2  3  4  5                   1  2                      1
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    2  3  4  5  6  7  8
13 14 15 16 17 18 19   10 11 12 13 14 15 16    9 10 11 12 13 14 15
20 21 22 23 24 25 26   17 18 19 20 21 22 23   16 17 18 19 20 21 22
27 28 29 30 31         24 25 26 27 28 29      23 24 25 26 27 28 29
                                              30 31
        April                   May                   June         
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
       1  2  3  4  5                1  2  3    1  2  3  4  5  6  7
 6  7  8  9 10 11 12    4  5  6  7  8  9 10    8  9 10 11 12 13 14
13 14 15 16 17 18 19   11 12 13 14 15 16 17   15 16 17 18 19 20 21
20 21 22 23 24 25 26   18 19 20 21 22 23 24   22 23 24 25 26 27 28
27 28 29 30            25 26 27 28 29 30 31   29 30

        July                  August                September      
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
       1  2  3  4  5                   1  2       1  2  3  4  5  6
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    7  8  9 10 11 12 13
13 14 15 16 17 18 19   10 11 12 13 14 15 16   14 15 16 17 18 19 20
20 21 22 23 24 25 26   17 18 19 20 21 22 23   21 22 23 24 25 26 27
27 28 29 30 31         24 25 26 27 28 29 30   28 29 30
                       31
       October               November               December       
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
          1  2  3  4                      1       1  2  3  4  5  6
 5  6  7  8  9 10 11    2  3  4  5  6  7  8    7  8  9 10 11 12 13
12 13 14 15 16 17 18    9 10 11 12 13 14 15   14 15 16 17 18 19 20
19 20 21 22 23 24 25   16 17 18 19 20 21 22   21 22 23 24 25 26 27
26 27 28 29 30 31      23 24 25 26 27 28 29   28 29 30 31
                       30

Print calendar for particular month and year

Use syntax as follows:
cal {month [1-12]} {year[1-9999]}
For example, display Jan-2007 calendar, enter:
$ cal 1 2007

Print the previous month

To print the previous month, the current month, and the next month all on one row, enter:
$ cal -3

Display Julian Calendar, if combined with the -e option, display date of easter according to the Julian Calendar.

$ cal -J

Display date of easter (for western churches)

$ cal -e

Print a calendar where Monday is the first day of the week, as opposed to Sunday.

$ cal -m

Display Julian days (days one-based, numbered from January 1).

$ cal -j

Display date of orthodox easter (Greek and Russian Orthodox Churches).

$ cal -o
Print the country codes and switching days from Julian to Gregorian Calendar as they are assumed by ncal. The country code as determined from the local environment is marked with an asterisk.
$ cal -p

Print the number of the week below each week column.

cal -w

Display a calendar for the current year.

$ cal -y

HowTo Format Date For Display or Use In a Shell Script

How do I format the date to display on the screen on for my shell scripts as per my requirements on Linux or Unix like operating systems?
[click to continue…]

Linux Set Date and Time From a Command Prompt

How can I set the system date and time from the command prompt (bash shell)? I don’t have GUI installed and I am login over ssh session. How can I set date under Linux operating systems?
[click to continue…]