Created
October 12, 2025 21:53
-
-
Save jdrews/0612c7623f6169b7c29f160a63006425 to your computer and use it in GitHub Desktop.
calculate the age of a system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Outputs something like this