Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • This doesn't work for me as the find just shows everything that exists. I also get weird results from the code in that variable: TIMEDIFF=$(( ( $(date --date="$(last -1 | head -n 1 | tr -s " " | cut -d" " -f3-6)" +%s) - $(date +%s) ) / 60 )) date: invalid date ‘134.29.149.192 Wed Jun 27’ Commented Jun 28, 2018 at 2:11
  • Fixed the oneliner, but requires GNU grep: TIMEDIFF=$(( ( $(date --date="$(last -1 $(whoami) | head -n 1 | grep -oP '\w{3} \w{3} \d{2} \d{2}:\d{2}')" +%s) - $(date +%s) ) / 60 )). Alternatively, if you're using bash, the $SECONDS variable might help you out more: TIMEDIFF="-$(( $SECONDS / 60 ))" Commented Aug 19, 2022 at 10:20