Current date and time in bash script

In Linux shell script you can use date command to get the current Date and time.
This command is part of the Linux coreutils package.

Basic date command uses

$ date
Tue Mar  7 10:20:12 IST 2019

$ currentDate=`date`
$ echo $currentDate
Tue Mar  7 10:20:12 IST 2019

Formatted date output

$ date +"%Y-%m-%d %T"
2019-02-21 11:20:12

For more information about date command you can see man pages.

$ man date
DATE(1)             User Commands
NAME       date - print or set the system date and time
SYNOPSIS
       date [OPTION]... [+FORMAT]
       date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
...

Deja una respuesta