Is it possible to easily format seconds as a human-readable time in bash?I don't want to format it as a date, but as the number of days/hours/minutes, etc...
Displaying seconds as days/hours/mins/seconds?
bash
You can use something like this:function displaytime {  local T=$1  local D=$((T/60/60/24))  local H=$((T/60/60%24))  local M=$((T/60%60))  local S=$((T%60))  (( $D > 0 )) && printf '%d days ' $D  (( $H > 0 )) && printf '%d hours ' $H  (( $M > 0 )) && printf '%d minutes ' $M  (( $D > 0 || $H > 0 || $M > 0 )) && printf 'and '  printf '%d seconds\n' $S}Examples:$ displaytime 116173 hours 13 minutes and 37 seconds$ displaytime 4242 seconds$ displaytime 66611 minutes and 6 seconds