Skip to content

Instantly share code, notes, and snippets.

@jdrews
Created October 12, 2025 21:53
Show Gist options
  • Select an option

  • Save jdrews/0612c7623f6169b7c29f160a63006425 to your computer and use it in GitHub Desktop.

Select an option

Save jdrews/0612c7623f6169b7c29f160a63006425 to your computer and use it in GitHub Desktop.
calculate the age of a system
#!/bin/bash
echo "System installed at $(stat -c %w /)"
INSTALL_DATE=$(stat -c %w /)
NOW_TIMESTAMP=$(date +%s)
INSTALL_TIMESTAMP=$(date -d "$INSTALL_DATE" +%s)
TIME_DIFF_SECONDS=$((NOW_TIMESTAMP - INSTALL_TIMESTAMP))
DAYS=$((TIME_DIFF_SECONDS / 86400))
REMAINDER_SECONDS=$((TIME_DIFF_SECONDS % 86400))
HOURS=$((REMAINDER_SECONDS / 3600))
REMAINDER_SECONDS=$((REMAINDER_SECONDS % 3600))
MINUTES=$((REMAINDER_SECONDS / 60))
SECONDS=$((REMAINDER_SECONDS % 60))
echo "Time difference: $DAYS days, $HOURS hours, $MINUTES minutes, $SECONDS seconds"
@jdrews
Copy link
Author

jdrews commented Oct 12, 2025

Outputs something like this

System installed at 2025-04-28 10:37:15.733432813 -0400
Time difference: 167 days, 7 hours, 14 minutes, 17 seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment