
Date command
Task Description: Explore date command and with options and try to use every option and create a simple document for it.
date command is used to display the system date and time. date command is also used to set date and time of the system. By default the date command displays the date in the time zone on which linux operating system is configured. You must be the super-user (root) to change the date and time.
=>man date
man date: shows the manual of date command
In manual we get to know how to use date command with options
=>date
the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the time zone name, and the year.
=>date — date=”11/19/2000"
date -d”11/19/2000"
— date or -d Option: Displays the given date string in the format of date. But this will not affect the system’s actual date and time value .Rather it uses the date and time given in the form of string.
we can use — date or -d option to see past and feature dates
=>date — set=”mon sep 21 15:13:12 IST 2000"
-s or — set Option: To set the system date and time.
=>date — file=”/root/Downloads/Datefile”
— file or -f Option: used to display the date string present at each line of file in the date and time format.This option is similar to –date option but the only difference is that in –date we can only give one date string but in a file we can give multiple date strings at each line.
=>watch date
watch date is used to see the live date and time .this option is similar to date command but the difference is watch date command shows live time with seconds running.
=>date +%D
+%D : Display date as mm/dd/yy format.
=> date “+%D %T”
+%D is used to see the date in dd/mm/yy format
%T is used display the time in 24 hours format as HH:MM:SS
=>date “+%Y — %m-%d”
+%Y is used to display four-digit year
%m is used to display month of the year(01 to 12)
%d is used to display day of the month(01 to 31)
=>date “+%A %B %d”
+%A is used to display full week days(sunday to saturday)
%B is used to display full month name (january to december)
%d is used to display the day of the month (01 to 31)
%T is used to display the time in 24 hour format as HH:MM:SS
%y is used to display last two digits of the year(00 to 99)
=>date “+%H :%M :%S”
+%H is used to display the Hour
%M is used to display the minutes
%S is used to display the seconds
=>a=$(date)
echo $a
we can store the output of the date command in a variable and we can echo the output of the date command with echo command
=>cal “$(date +%B)”
cal is used to display the calender
we can take output of date command as a input to the cal aommand to display the calender.
========================================
*to know more about date command you can go to man date (or)date — help