How To Get / Print Current Date in Unix / Linux Shell Script
Current date in Unix or Linux shell scripting and store it into a shell variable? How do I print the current date using Unix shell script? How can I display the current time in Linux shell script? \
You need to use the following syntax to print current date and time on screen:ADVERTISEMENT\
Print current date and time in Unix shell script
To store current date and time to a variable, enter:
now=$(date)
OR
now=`date`
Print Current Date in Unix
To print this date either use the printf or echo statement:
echo "$now"
echo "Current date: $now"
OR use the printf command:
printf "%s\n" "$now"
OR
printf "Current date and time in Linux %s\n" "$now"
Getting the current date and time in Linux shell script
You can format and display date using the following syntax:
Finding the current date and time in Linux or Unix using the date command
A list of date command format codes
Sample shell script to display the current date and time
\
Last updated