get only the date of last command in Linux (fromt the last login)

Viewed 19

last command in linux shows the last logins in the system.

Is there any script that I can retrive only the date of the these last logins?

thanks

2 Answers

Quick n dirty

$ last | grep -v "system boot" | awk '{for (i=4; i<NF; i++) printf $i " "; print $NF}'
last | {m,g}awk 'gsub(/\t/, " ", $!(NF *= /system boot/))^_ * NF' \
                 FS='^[ \t]*[^ \t]*[ \t]+[^ \t]*[ \t]+[^ \t]*[ \t]+' OFS=

I only have macos ~ (BSD 4.4) and not Linux here so I can't test the output of it (even the last command looks different here). Let me know if this works or not.

If you don't care for that final gsub() bit that's more nice to have than essential, then the body is even simpler :

{m,g}awk 'NF *= /system boot/' { FS=... OFS=... }
Related