
jsadebugd Command in Linux
lastcomm is a Linux command that allows users to display information about the last executed commands on the system. This command shows details like the user who ran the command, the command itself and the time it was executed. This command is pretty useful for system administrators who want to monitor user activities or analyse command usage patterns.
By default, lastcomm lists all recorded commands, but you can also filter the output by specifying a particular user, command, or terminal. This helps in tracking specific activities or investigating unusual behaviour on the system.
Table of Contents
Here is a comprehensive guide to the options available with the lastcomm command −
- How to Install and Enable lastcomm Command in Linux?
- Syntax for lastcomm Command
- Options Available for lastcomm Command
- Examples of lastcomm Command in Linux
How to Install and Enable lastcomm Command in Linux?
By default, the lastcomm command is not installed on the Linux system, but you can easily add it by installing the acct package from the Linux repository. Here are the commands for different Linux distributions −
Debian-based Systems (e.g., Ubuntu)
sudo apt install acct
RHEL-based systems (e.g., CentOS, Fedora)
sudo yum install psacct
Arch Linux
sudo pacman -S acct
OpenSUSE
sudo zypper install acct
Syntax for lastcomm Command
The general syntax for lastcomm command on Linux is as follows −
lastcomm [options] [command-name] [user-name] [terminal-name]
Where,
- [options] are various options to modify the output.
- [command-name] is the name of the command you want to look up.
- [user-name] is the username of the user whose command history you want to view.
- [terminal-name] is the terminal from which the command was executed.
Options Available for lastcomm Command
There are different options that can be used with the command lastcomm, these are discussed in the table provided below −
Option | Description |
---|---|
--ahz hz | Specify the AHZ value (in hertz) for the program. |
--command name | List records for the specified command name. |
--debug | Enable debugging output. |
--file filename | Load from the designated file rather than the default account file. |
--forwards | Process the file in a forward direction rather than in reverse. |
--pid | Display the Process ID (PID) and Parent Process ID (PPID) of the process, provided the kernel supports it. |
--print-controls | Output the control characters. |
--show-paging | Display paging statistics. |
--strict-match | Output only the entries that meet all the given criteria. |
--tty name | Show records associated with the given terminal name. |
--user name | Show records for the specified user name. |
Examples of lastcomm Command in Linux
Let's explore a few examples of the Linux lastcomm command −
- List All Recent Commands
- Display Command Executed by a Specific User
- Display Information about a Specific Command
- Display Commands Executed on a Specific Terminal
- Display Commands Executed by a Specific User on a Specific Terminal
List All Recent Commands Executed
The basic use of the lastcomm command is to quickly view a list of all recent commands executed on the system. This list includes the command names, usernames, terminal names, and execution times. You can achieve this by simply executing the following command −
lastcomm

Display Commands Executed by a Specific User
If you want to limit the output to commands executed by a specific user, you can use the --user option followed by the username. This is useful when you need to track the activities of a particular user. For example, to show commands executed by the user ubuntu, use the command −
lastcomm --user ubuntu

Display Information About a Specific Command
Sometimes, you might want to see details about a specific command, which can be done using the --command option with the command name. To display information about the ls command, simply run the following command −
lastcomm --command ls
Display Commands Executed on a Specific Terminal
To focus on commands executed on a specific terminal, you can use the --tty option with the terminal name. This can be helpful for monitoring activities on a particular terminal; for example, to show commands executed on terminal tty1, use the command −
lastcomm --tty tty1
Display Commands Executed by a Specific User on a Specific Terminal
For more granular tracking, you can combine options to filter the results. To display commands executed by the user ubuntu on terminal tty1, use the following command −
lastcomm --user ubuntu --tty tty1
Conclusion
The lastcomm command is an essential tool for system administrators to monitor command usage and user activities on Linux systems. This tutorial has detailed the basic syntax, various options, and practical examples of using the lastcomm command.
Whether you need to view all recent commands, focus on a particular user's activities, or monitor commands executed on a specific terminal, lastcomm offers a comprehensive and efficient way to manage and audit system usage.