How to get the current Unix timestamp or epoch time from a Linux command line

Linux date command is a very powerful utility to get or set system time in various ways. Let us check, how to get Unix timestamp from a Docker container, Linux / Ubuntu terminal.

Echo Unix timestamp using the date command

date +%s

Example:

$ date +%s
1262322642

By default, the Unix timestamp (epoch) is calculated in UTC, so there will be no difference in it regardless of the timezone.

Example in an Ubuntu terminal / command line

print current Unix timestamp/epoch time

Storing timestamp in a bash script variable, and echo it

$ timestamp=$(date +%s)
$ echo $timestamp
1262322992

What is epoch time (Unix timestamp)?

The Unix epoch is the time 00:00:00 UTC on 1 January 1970. The current epoch time is the number of seconds counted from there. Reference: https://en.wikipedia.org/wiki/Unix_time