How to Convert a Linux Epoch Timestamp to Date on the Command Line
The date command is a standard Unix utility that displays and manipulates the dates and times. It is the pre-installed utility in most Linux distributions and can convert an epoch timestamp to a human-readable date and time. Run the following command to convert an epoch timestamp:
In the previous command, you can replace the as the number of seconds since January 1, 1970 at 00:00:00 UTC.
For example, to convert the epoch timestamp 1674000000 which corresponds to January 18, 2023 at 00:00:00 GMT, use the following command:
The -d option specifies the date and time in a format that is understood by the date command. The “@” symbol indicates that the argument is an epoch timestamp instead of a different time format.
The date command supports several different output formats which you can specify using the + option and a format string. For example, to display the date and time in the YYYY-MM-DD HH:MM:SS format, use the following command:
You can find more information on the format codes on the manual date page (man date).
Conclusion
This is all about the simple way to convert a Linux epoch timestamp to date on the command line. This can be useful for converting timestamps in log files, database entries, and other data sources into an easier-to-read and understandable format. With a simple command line argument, you can quickly and easily convert an epoch timestamp into a date and time that is usable for your purposes.