Unix timestamps—also known as Epoch time or POSIX time—measure system time as the total number of elapsed seconds since 00:00:00 Coordinated Universal Time (UTC) on 1 January 1970, excluding leap seconds. Because Epoch integers are compact, timezone-independent, and easy for computers to sort numerically, they are ubiquitous across server log files, database transaction tables, API payloads, and file metadata.
However, an integer like 1730048400 is virtually unreadable to human administrators troubleshooting incidents or reviewing system security events. Fortunately, GNU coreutils includes the versatile date utility, which can translate raw Epoch seconds into human-readable date and time strings directly in the Linux terminal without requiring external scripting languages like Python or Perl.
Understanding the Syntax for Converting Epoch Timestamps
The GNU date command provides the -d (or --date) parameter to parse custom date strings. To specify that an input string represents a raw Unix timestamp rather than a formatted calendar date, prefix the integer with an @ symbol:
date -d @<timestamp>
For example, to convert the timestamp 1730048400 into the local system time:
date -d @1730048400
Output:
Sun 27 Oct 2024 17:00:00 GMT
The command parses the integer and displays the corresponding day of the week, calendar date, time, and active timezone abbreviation configured on your host system.
Converting Unix Timestamps to UTC Time
When auditing distributed application logs or reviewing server activity across multiple international regions, converting timestamps to UTC prevents confusion caused by local daylight saving time offsets. Add the -u (or --utc) flag to output the time in UTC:
date -u -d @1730048400
Output:
Sun 27 Oct 2024 17:00:00 UTC
Formatting the Date Output with Custom Specifiers
The date command allows you to define custom output structures using standard format specifiers prefixed with a plus sign (+). This is particularly useful when parsing timestamps inside Bash deployment scripts or formatting tabular reports:
Common Format Specifiers
%Y: Four-digit year (e.g.,2024)%m: Two-digit month (01to12)%d: Two-digit day of the month (01to31)%H: Hour in 24-hour format (00to23)%M: Minute (00to59)%S: Second (00to59)%Z: Timezone name or abbreviation (e.g.,UTC,BST)%F: Full ISO-8601 date shortcut (equivalent to%Y-%m-%d)%T: Full 24-hour time shortcut (equivalent to%H:%M:%S)
Examples of Custom Formats
To output a clean ISO-8601 formatted date and time string:
date -u -d @1730048400 +"%Y-%m-%d %H:%M:%S %Z"
Output:
2024-10-27 17:00:00 UTC
To extract only the calendar date in standard UK notation (DD/MM/YYYY):
date -d @1730048400 +"%d/%m/%Y"
How to Convert Current System Time to a Unix Timestamp
In addition to decoding timestamps, the date utility can generate Unix timestamps from current system time or historical dates using the %s specifier:
To view the current Unix timestamp in real time:
date +%s
To convert a specific calendar date and time into its Epoch equivalent:
date -d "2024-10-27 17:00:00 UTC" +%s
Output:
1730048400
Batch Converting Timestamps in Log Files Using awk
If you have log files containing Epoch timestamps at the beginning of each line, running individual terminal commands for each entry is impractical. You can combine awk with strftime to process entire log files in one pass:
awk '{$1 = strftime("%Y-%m-%d %H:%M:%S", $1); print}' access.log
This command interprets the first column ($1) of each line as a Unix timestamp, replaces it with a clean formatted date string, and prints the updated log line to the standard terminal output, simplifying incident investigation across high-volume Linux servers.