Bourne
Bourne

Reputation: 1927

Linux command to display date in unix format

What command can I use in linux to display the time in unix format i.e. no of seconds since epoch (01/01/1970)?

Upvotes: 3

Views: 12878

Answers (3)

Stephane Chazelas
Stephane Chazelas

Reputation: 6239

GNU and BSDs:

date +%s

With most Awk implementations:

awk 'BEGIN{srand(); print srand()}'

Probably the most portable out of Linux:

perl -le 'print time'

With shell builtin, ksh93 or Bash 4.1 or above:

printf '%(%s)T'

With shell builtin, zsh:

zmodload zsh/datetime
echo "$EPOCHSECONDS"

Upvotes: 4

Igor Chubin
Igor Chubin

Reputation: 64563

Just use this command:

date +%s

Upvotes: 4

Ye Liu
Ye Liu

Reputation: 8976

You should use date command with format: date +%s

Upvotes: 7

Related Questions