Unix timestamp is the number of seconds that have elapsed since the Unix Epoch (January 1, 1970, at 00:00:00 UTC). It serves as a universal timekeeping standard and is commonly used in various programming applications, system logging, and data exchange. On Linux systems, obtaining the current Unix timestamp is a straightforward process that can be achieved using various methods. This tutorial provides 2 methods how to get the current Unix timestamp on Linux.
Method 1 - date command
The simplest and most common way to obtain the current Unix timestamp on a Linux system is by using the date command.
date +%s
The %s format specifier instructs the date command to display the timestamp in seconds since the epoch.
Output example:
1689729935
Method 2 - EPOCHSECONDS variable
In the Linux environment, the EPOCHSECONDS variable is a convenient feature that allows to access the current Unix timestamp directly without using external commands.
echo $EPOCHSECONDS
Leave a Comment
Cancel reply