> For the complete documentation index, see [llms.txt](https://linux-tutorial-cli.gitbook.io/linux-cli-tutorial/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://linux-tutorial-cli.gitbook.io/linux-cli-tutorial/txt-files/file-systems-cocepts/lpic2-201/udevadm-monitor.md).

# udevadm monitor

The `udevadm monitor` command in Linux is used to monitor udev events in real-time. Here’s a detailed explanation of what `udevadm monitor` does and how it is used:

### Purpose of `udevadm monitor`

1. **Event Monitoring**:
   * `udevadm monitor` allows users to monitor and view udev events as they occur on the system.
   * It provides real-time information about devices being added, removed, or changed, and the corresponding actions taken by `udev`.
2. **Device Management**:
   * It helps in debugging and managing device-related issues by providing insight into how devices are detected and handled by the system.

### How to Use `udevadm monitor`

* **Basic Usage**: To start monitoring udev events, simply execute `udevadm monitor` in a terminal with root privileges.

  ```bash
  sudo udevadm monitor
  ```
* **Example Output**:

  ```
  KERNEL[1641621477.626526] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1 (usb)
  ACTION=add
  DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1
  SUBSYSTEM=usb
  ```
* **Options**: `udevadm monitor` supports various options to customize the output or filter events based on specific criteria:
  * `-h`, `--help`: Display help information about `udevadm monitor`.
  * `-k`, `--kernel`: Monitor kernel events.
  * `-u`, `--subsystem-match=subsystem`: Filter events by subsystem (e.g., `usb`, `input`).
  * `-e`, `--environment`: Print the environment with each event.
* **Example Usage**:
  * Monitor only events related to the `usb` subsystem:

    ```bash
    sudo udevadm monitor --subsystem-match=usb
    ```

### Usage Scenarios

* **Device Detection**: Monitor how devices are detected and initialized by the system.
* **Rule Testing**: Develop or test udev rules and configurations by observing their impact on device handling.
* **Debugging**: Troubleshoot device-related issues by observing udev events and their associated actions in real-time.

### Conclusion

`udevadm monitor` is a powerful command-line tool in Linux for monitoring udev events dynamically. It provides administrators, developers, and users with visibility into the device management processes of the Linux kernel, aiding in troubleshooting and debugging device-related issues effectively. By understanding and utilizing `udevadm monitor`, Linux users can gain insights into the dynamic device management processes that underpin the operating system's functionality.
