2

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,687
  • 11
  • 30
  • 50
  • 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,826
  • 1
  • 35
  • 32
4

Just use this command:

date +%s
Igor Chubin
  • 51,940
  • 8
  • 108
  • 128
3

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"
Steven Penny
  • 82,115
  • 47
  • 308
  • 348
Stephane Chazelas
  • 5,014
  • 2
  • 27
  • 29