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

Unix timestamp or epoch time is one of the most popular and easily generatable timestamp formats, quickly in a bash shell. 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


$ date +%s

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

For 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

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:

Here is another guide to getting the formatted time using the date command, such as year to seconds