Monitor Users and System Activity with the Linux w Command

Monitor Users and System Activity with the Linux w Command

The w command in Linux is a very powerful tool that provides details about users who are currently logged in to the system, as well as their actions. It assists administrators in observing user activity and monitoring the performance of the system. Moreover, it shows a list of the users who are currently logged in, their login information, and the commands they’re executing.

In this article, we’ll examine the w command in depth and provide various usage examples.

Table of Contents

Hide ▲

Key Takeways

  • Lorem Ipsum dolor sit
  • Lorem Ipsum dolor sit
  • Lorem Ipsum dolor sit
  • Lorem Ipsum dolor sit
  • Lorem Ipsum dolor sit
  • Lorem Ipsum dolor sit

Exploring the w Command in Linux with Examples

The w command on Linux offers a brief overview of the system’s current activities. It displays currently logged-in users and important system-wide metrics. This information is useful to system administrators and users alike to track the performance of the system.

Furthermore, the w command provides the system’s overall activity over the last 1, 5, or 15 minutes. This data is essential for system administrators to keep track of the users’ activity, spot the possibility of performance bottlenecks, and troubleshoot issues with the system.

General Syntax

You can execute the w command with the following syntax to monitor users and system activities:

w [options]

The command w gives an overall view of the situation of the system and the activity of users when executed without options.

Basic Usage

Let’s begin with the basics of using the command w. In your terminal, enter the following command:

w
basic usage w command

The output includes the following details:

  • Time: The current system time.
  • Uptime: The length of time since the system has been operating.
  • User: It is the number of people who are currently logged in
  • Load Average: This is the average system load in the last one, five, and fifteen minutes.
  • USER: The login name that the individual user uses.
  • TTY: It is the terminal that is associated with the user.
  • FROM: This user has logged in via the host remotely.
  • LOGIN@: The username is the time that the user has to log in.
  • IDLE: The idle period that the individual user has.
  • JCPU: It shows the total CPU time used by all terminal-attached processes.
  • PCPU: The Amount of CPU that the process in use is making use of.
  • WHAT: The command the user is running currently.

Enjoy a Seamless Hosting Experience with HostOnce’s Linux VPS!

Experience the power of HostOnce’s Linux VPS—customize your hosting with ease and enjoy reliable performance, top-notch security, and smooth uptime.

Common Options with the w Command

The w command has many options that allow you to modify the output. Here are some common options users often use with the w command:

  • h: Blocks the line in the header.
  • s: Uses the format of a short form, showing only the username, terminal, and the time to log in.
  • u: Disregards the username in computing the current processes and CPU time.
  • f: Switches print of “from” field (remote hostname). By default, it’s not printed.
  • i: Displays that IP address inside “from”, not in the “from” field, rather than the hostname.
  • o: Prints blank spaces for idle time that is under one minute.
  • V: Displays the version information on the command w.
  • help: Displays a help screen that provides details on how to utilize and set up the W command.

How to Use the w Command in Linux?

Let’s look at some examples of the w command to see how it helps us monitor the logged-in users and system activities:

Example 1: Displaying All User Information

Simply run the command w without options to view the details of every user who is logged on to the system currently:

w

It provides a comprehensive list of all active users logged in, along with their terminal, login time, idle time, and the commands they are running. It also displays the system’s uptime and load average:

display information of all users

Example 2: Displaying Information for a Specific User

To display data for a specific user, such as linuxuser, you can use the following command:

w linuxuser

Replace linuxuser with the real username. This will only show information for the user that is specified.

specific user details

Example 3: Displaying User Information Without the Header

You can use the -h option to display user information without a header:

w -h

This option eliminates the header line that includes information about the system, resulting in an easier-to-read output:

human friendly output

Example 4: Displaying User Information in Short Format

To display information for users in a smaller format, select the -s option:

w -sf

This option shows a smaller output, displaying only your username and terminal, and the time to log in:

smaller output

Example 5: Ignoring Username

If you want to ignore the current process username, use the w command with the -u option:

w -u

This option does not consider any username associated with the process currently in use while determining the activity of the user:

ignore specific user

Example 6: Toggling the FROM Field

Users can also hide or show the hostname field of a remote host using the option -f:

w -f

In the FROM field, which shows the hostname of the remote host or IP address from where the user was logged in, may be switched on using the option -f:

toggling the form field

Example 7: Displaying IP Address Instead of Hostname

Let’s display IP addresses in the FROM field:

w -i

Within the FROM section, this option will show the IP address instead of the hostname:

display ip address instead of hostname

Example 8: Old Style Output

If you want to display output using a traditional format, use the option -o:

w -o

The above flag represents the output in an old-style format. It is helpful to make it compatible with older operating systems:

old style output

Example 9: Displaying Version Information

After that, display the version of the command w using the option -V:

w -V

This option shows the version details of the w command:

version information

Example 10: Getting Help

The utility --help is a different option for users to look up the help content:

w --help

As a result, it displays all available options along with their descriptions:

w command help

This way, you can utilize these options by using the command w to meet your needs specifically and gather the information you require about the system’s activity and sessions.

Alternative Commands to w in Linux

The w command shows logged-in users, their activities, and system load. Other Linux commands provide similar or complementary details for uptime, logins, or processes. Here’s a comparison to help you choose the right tool for your needs:

CommandPurposeKey OutputWhen to Use
whoLists logged-in usersUsername, terminal, login timeUse when you only want to know who is logged in without system or process info.
usersShows a list of current usernamesJust the usernames (space-separated)Ideal for quick, minimal output of active users.
uptimeDisplays system uptime and loadTime, uptime, number of users, load averagesUse when you’re mainly interested in how long the system has been running and how busy it is.
topReal-time process monitoringCPU, memory usage, process list, and user activityBest for in-depth performance analysis and real-time tracking of system resource usage.
htopEnhanced version of the top with UIInteractive view of system resourcesUse when you want a user-friendly, color-coded interface for monitoring processes.
psDisplays current processesProcess ID, user, CPU/memory usage, commandUseful for viewing specific processes or filtering by user.
lastShows login historyPrevious user logins with time and sourceHelpful for auditing and seeing who logged in and when
whoamiShows the current usernameThe logged-in user’s nameHandy for scripting or confirming user identity
idDisplays user ID and group IDUID, GID, groupsUse for checking user permissions and group access.

That’s all about using the w command for monitoring the activities of system users and logged-in users. You can explore more interesting Linux tutorials and how-to guides by visiting our Knowledge Base.

Conclusion

The w command in Linux lets you see in real time who’s logged in and what they’re doing. It’s useful for both system administrators monitoring user activity and regular users checking system performance. In this article, we explain how to use the w command’s simple syntax and options to display details ranging from login information to CPU usage.

Anees Asghar Avatar

FAQs

To display information about an individual user, enter the username in the argument, such as w username. Replace username with your actual username.

The -h option eliminates the header line, which includes information about the system, resulting in more precise output.

To change between the displays OF the FROM field that displays the hostname of the remote server as well as the IP address where the user was logged in, use the -f option.

To show your IP address in place of hostname within the FROM field, select the -i option.

Author: Anees Asghar

Anees is a seasoned technical writer and WordPress expert with over 5 years of experience building and optimizing WordPress solutions. He also writes on Windows, Linux, MySQL, Java, and other technologies, creating practical content that helps developers and IT professionals.

Post a Comment

Your email address will not be published. Required fields are marked *