3

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

Bourne
  • 1,905
  • 13
  • 35
  • 53
  • possible duplicate of [get current time in seconds since the Epoch on Linux, Bash](http://stackoverflow.com/questions/1092631/get-current-time-in-seconds-since-the-epoch-on-linux-bash) – Alex K. Jun 10 '13 at 14:21
  • 1
    Check the man pages for stuff like this, it'll save you time - looking at `man date` will show you this note: `%s seconds since 1970-01-01 00:00:00 UTC` – Mike Jun 10 '13 at 14:21

3 Answers3

7

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

Ye Liu
  • 8,946
  • 1
  • 38
  • 34
4

Just use this command:

date +%s
Igor Chubin
  • 61,765
  • 13
  • 122
  • 144
4

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"
Zombo
  • 1
  • 62
  • 391
  • 407
Stephane Chazelas
  • 5,859
  • 2
  • 34
  • 31