Unix Timestamp in Bash / Shell
Bash can get Unix timestamps with the date command (GNU coreutils or macOS BSD). These one-liners are useful in scripts, cron jobs, and DevOps automation.
Code Examples
Current timestamp (seconds) — Linux/macOS
date +%s
Works on Linux (GNU date) and macOS (BSD date). Prints the current Unix timestamp in seconds. The most common shell timestamp command.
Current timestamp (milliseconds) — Linux
date +%s%3N
GNU date only (Linux). %s is seconds, %3N is nanoseconds truncated to 3 digits (milliseconds). Not available on macOS BSD date.
Current timestamp (milliseconds) — macOS
python3 -c 'import time; print(int(time.time() * 1000))'
macOS BSD date doesn't support %N. This Python one-liner works on any system with Python 3 installed.
Convert timestamp to human-readable date — Linux
date -d @1708560000
GNU date: the @ prefix treats the argument as a Unix timestamp. Add -u for UTC output: date -u -d @1708560000.
Convert timestamp to human-readable date — macOS
date -r 1708560000
BSD date (macOS): use -r instead of -d @. Add -u for UTC: date -u -r 1708560000.
Store timestamp in a variable
TS=$(date +%s) echo "Backup started at $TS"
Command substitution captures the output. Useful for logging, naming backup files, or measuring elapsed time in scripts.
Note
GNU date (Linux) and BSD date (macOS) have incompatible flag syntax — %N for nanoseconds works on Linux but not macOS, and -d @timestamp works on Linux while macOS uses -r timestamp. For cross-platform scripts, use Python or Node.js for timestamp operations instead of relying on date flags.
Main Epoch Converter
Use the homepage when you need epoch to date, date to epoch, or a full epoch converter
This Bash / Shell guide shows how to create and parse Unix timestamps in code. If your next step is broader search intent like epoch converter, epoch to date, epoch time to date, or unix epoch converter, jump back to the live homepage tools to paste a raw Unix value, auto-detect seconds versus milliseconds, and copy the readable answer instantly.