There are many ways to convert from Unix timestamps into a human-readable format. You can use either one of the many online converters, like unixtimestamp.com, or your command line (CLI). But converting a list with many timestamps. But converting a list with many timestamps can be tedious if done manually. This little Bash script will take care of this for you.
tl;dr
Copy and paste this bash code into a file, make it executable, and move it into /usr/local/bin
. Run with timestamps "<timestamps>"
.
The Code
Create a script file, e.g., timestamps.sh
, and open it with a text editor. As a side note, I’m currently using Zed for macOS because it’s super fast and even has free AI support.
#!/bin/bash
# Function to convert timestamps to human-readable format
timestamps() {
# Loop through each timestamp passed as an argument
for ts in $1; do
# Convert to human-readable format
readable_date=$(date -r ${ts%.*} +"%Y-%m-%d %H:%M:%S")
echo "$ts -> $readable_date"
done
}
# Check if the script is being sourced or executed
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
# If executed directly, call the function with the provided arguments
timestamps "$@"
fi
BashMake it globally available in CLI
Turn the script into an executable file:
# Make it executable
chmod +x timestamps.sh
BashAfter that, rename and move the now-executable script into a directory that is contained in the $PATH
environment variable (you can check the directories by running echo $PATH
). For custom scripts like this, I personally use /usr/local/bin
:
mv timestamps.sh /usr/local/bin/timestamps
BashClose your terminal and open it again. You can now convert one or more timestamps into a human-readable format. Just make sure to separate each timestamp by a space and put them in quotes altogether.
Example: One Timestamp
# Command
timestamps 1759774710
# Output
1759774710 -> 2025-10-07 01:18:30
BashExample: Multiple Timestamps
# Command
timestamps "1760891188.438359 1729449634.348971"
# Output
1760891188.438359 -> 2025-10-19 23:26:28
1729449634.348971 -> 2024-10-21 01:40:34
BashDon’t forget to wrap multiple timestamps into single or double quotes, as seen in the last example.
Happy converting!
The code or instructions don’t work or display an error? Please let me know so I can fix it quickly.