- [Instructor] Hello again, and welcome
to the next video of section eight,
Collecting Information about Logged-in Users,
Boot Logs, and Boot Failures.
In the previous video, we've learned how
to calculate the execution time for a command.
This video, we'll go through a few commands used
to gather information about a live machine.
Collecting information about the operating environment,
logged-in users,
the time for which the computer has been powered on,
and the boot failures are very helpful.
This section will introduce commands who, w, users,
uptime, last, and lastb.
Let's see how to do it.
To obtain information about users
currently logged into the machine use...
This output lists the login name,
the TTY used by the users,
login time, and remote hostname,
or X display information about logged-in users.
TTY, the term comes from teletypewriter,
is the device file associated with a text terminal,
which is created in /dev
when a terminal is newly spawned by the user,
for example, /dev/pts/3.
The device path for the current terminal can be found out
by typing and executing the command tty.
To obtain more detailed information
about the logged-in users, use...
This first line lists the current time,
system uptime, number of users currently logged on,
and the system load averages
for the past one, five, and 15 minutes.
Following this, the details about each login are displayed
with each line containing the login name, the TTY name,
the remote host, login time, idle time,
total CPU time used by the user since login,
CPU time of the currently running processes,
and the command line of their current process.
Load average in the uptime command's output is
a parameter that indicates system load.
In order to list only the usernames
of the users currently logged into the machine, use...
If a user has opened multiple terminals,
it will show that many entries for the same user.
In the preceding output, the user slynux
has opened three pseudo terminals.
The easiest way to print unique users is
to use sort and uniq to filter as follows.
We've used tr to replace this with this.
Then a combination of sort and uniq
will produce unique entries for each user.
In order to see how long the user has been powered on,
use...
The time that follows the word up indicates the time
for which the system has been powered on.
We can write this simple one-liner
to extract the uptime only.
This uses grep with a Perl-style regex
to extract only three two-digit numbers separated by colons.
In order to get information on previous boot
and user logged-in sessions, use...
The last command will provide information
about the logged-in sessions.
It's actually a log of system logins that consists
of information such as tty from which it has logged in,
login time, status, and so on.
The last command uses the log file /var/log/wtmp
for the input log data.
It's also possible to explicitly specify the log file
for the last command using the minus f option, for example.
In order to obtain information about login sessions
for a single user, use...
Get information about reboot sessions as follows.
In order to get information
about failed user login sessions, use...
You should run lastb as the root user.
Awesome, we've successfully learned about collecting
information about logged-in users, boot logs, and boot.
In the next video, we'll learn about listing
the top 10 CPU-consuming processes in an hour.