Shell Script: Get Epoch Time

Unix time, POSIX time or Epoch time is defined as the number of seconds that have elapsed since 00:00:00 January 1, 1970 UTC. There are a few methods to retrieve the Epoch time on Unix and Linux.

Epoch Time with GNU date

On Linux or any systems with the GNU date installed, just specify the “%s” format to the date command.

Epoch Time with Perl

If GNU date is not available, such as on Solaris system, perl can be used.

Epoch Time with Python

Python can also be used to retrieve the Epoch time. On Python 2.x, use the following syntax.

On Python 3.x, use the new syntax below.

Epoch Time with Awk

The final method is to use the pattern scanning and text processing tool – awk.

If the awk command gives syntax errors, especially on Solaris systems, replace awk with nawk instead.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }