DEV Community

Simon Justesen
Simon Justesen

Posted on

Linux/Unix login overview and a bit of clever tricks with "history"

See who's logged in to your Linux/Unix box:

Go to the terminal and type

$ w (or who) 
Enter fullscreen mode Exit fullscreen mode

at the prompt followed by enter - then you will get a list of active users and the last used IP address when they were logged in.

If you want to know who has been logged in sometime in the past, you can use 'last' in the terminal.

$ last -s "-3 weeks"
Enter fullscreen mode Exit fullscreen mode

will give you an overview of users who have been logged in for the past 3 weeks.

You can always look in the man(ual) to see what other options you have with a command.

$ man who
Enter fullscreen mode Exit fullscreen mode

Avoid typing too much with "history" :)

$ history
Enter fullscreen mode Exit fullscreen mode

will give you a summary of the most recently executed commands. You can then choose to pip the output on to 'less' to get a scrollable overview or 'grep' to search more in-depth.

$ history | grep -i "ssh"
Enter fullscreen mode Exit fullscreen mode

gives you an overview of used ssh commands and their arguments.

Did you notice the number to the left of the command? You can use the number to run a command again! That's a nifty way of avoiding having to either type in the command again or keep bashing Page Up until you discover the command wanted again ;).

Say you want to rerun the command at entry 1115... Just type:

!1115
Enter fullscreen mode Exit fullscreen mode

One final trick: If you type double exclamation marks !!, the system will rerun the last command, you entered.

Cheers!

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

đź‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay