udevadm

system administrationLinux
The udevadm command is one of the most frequently used commands in Linux/Unix-like operating systems. udevadm udev management tool for device detection and configuration

Quick Reference

Command Name:

udevadm

Category:

system administration

Platform:

Linux

Basic Usage:

udevadm [options] [arguments]

Common Use Cases

    Syntax

    udevadm [--help] [--version] [--debug] COMMAND [OPTIONS]

    Options

    The udevadm command has several sub-commands, each with their own options:

    Main Options

    Option Description
    --debug Print debug messages to stderr
    --version Print version of the program
    --help Print help text

    Sub-commands

    Command Description
    info Query sysfs or the udev database
    trigger Request events from the kernel
    settle Wait for pending udev events
    control Control the udev daemon
    monitor Listen to kernel and udev events
    test Test an event run
    test-builtin Test a built-in command

    Common Options for 'info' Sub-command

    Option Description
    --query=TYPE Query mode (name, path, property, all)
    --name=DEVNAME Name of device to query
    --path=DEVPATH Path of device to query
    --attribute-walk Print all sysfs properties

    Common Options for 'monitor' Sub-command

    Option Description
    --kernel Print kernel events
    --udev Print udev events
    --property Print device properties
    --subsystem-match=SUBSYSTEM Filter by subsystem

    Common Options for 'trigger' Sub-command

    Option Description
    --action=ACTION Event action (add, change, remove)
    --subsystem-match=SUBSYSTEM Trigger devices from a subsystem
    --attr-match=ATTRIBUTE=VALUE Trigger devices with a specific attribute
    --verbose Print the list of devices that will be triggered

    Common Options for 'control' Sub-command

    Option Description
    --reload-rules Reload rules files
    --start-exec-queue Start execution of events
    --log-priority=LEVEL Set log level (err, info, debug...)
    --exit Signal udevd to exit

    Examples

    How to Use These Examples

    The examples below show common ways to use the udevadm command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    # Get information about a device sudo udevadm info --name=/dev/sda
    # Monitor udev events in real-time sudo udevadm monitor
    # Reload udev rules without rebooting sudo udevadm control --reload-rules
    # Trigger udev events for all devices sudo udevadm trigger
    # Advanced Examples Advanced
    # Get all udev properties for a specific device sudo udevadm info --attribute-walk --name=/dev/sda # Monitor only device events (not udev events) sudo udevadm monitor --kernel # Monitor only USB devices sudo udevadm monitor --subsystem-match=usb # Trigger events for specific subsystem sudo udevadm trigger --subsystem-match=usb # Test a device against the udev rules sudo udevadm test $(udevadm info --query=path --name=/dev/sda) # Watch a specific device for changes sudo udevadm monitor --property | grep /dev/sda # Force kernel to rescan for devices sudo udevadm trigger --action=add # Trigger events for a specific sysfs path sudo udevadm trigger --attr-match=idVendor=1234 # Settle all pending udev events sudo udevadm settle # Get detailed debugging information for device sudo udevadm info --name=/dev/sda --attribute-walk

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The `udevadm` command is a powerful utility for managing and interacting with udev, the device manager for the Linux kernel. It provides an interface to the udev system, allowing administrators and users to query device information, monitor hardware events, trigger device events, and control the udev daemon itself. Udev is responsible for dynamic device detection and management in Linux. When hardware is added, removed, or changed, the kernel sends events that udev processes, applying rules to create device nodes, set permissions, execute programs, and more. The `udevadm` tool gives you access to all these functions. Here's a deeper look at its key capabilities: 1. **Device Information Retrieval**: With the `info` subcommand, you can query detailed information about devices, including their attributes, properties, and relationships in the system hierarchy. This is invaluable for troubleshooting hardware issues or writing udev rules. 2. **Event Monitoring**: The `monitor` subcommand allows you to observe device events in real-time, seeing exactly what happens when devices are plugged in, removed, or otherwise changed. This is useful for debugging device recognition problems. 3. **Rule Management**: Through the `control` subcommand, you can reload udev rules without rebooting, making it easier to develop and test new rules for device management. 4. **Event Generation**: The `trigger` subcommand lets you manually generate udev events for devices, which is helpful when you've changed rules and want to apply them to existing devices without physically disconnecting and reconnecting them. 5. **Rule Testing**: With the `test` subcommand, you can simulate what would happen when a device event occurs, without actually making any changes to the system. This is valuable for safely developing and testing udev rules. 6. **Event Synchronization**: The `settle` subcommand waits for all pending udev events to be processed, which is important in scripts that need to ensure all device setup is complete before proceeding. The `udevadm` tool is essential for system administrators working with hardware, particularly in scenarios involving custom device setups, automated device configuration, persistent device naming, or hardware troubleshooting. It's also valuable for developers creating applications that interact with hardware or writing udev rules to automate device handling. While powerful, `udevadm` often requires root privileges for many operations, as it interacts directly with system hardware and the udev daemon, which runs with elevated permissions. Additionally, incorrect use of commands like `trigger` or `control` could potentially disrupt system hardware functionality, so it should be used with care. Overall, `udevadm` represents a comprehensive interface to the Linux device management subsystem, providing the tools needed to understand, monitor, and control how the system interacts with hardware devices.

    Related Commands

    These commands are frequently used alongside udevadm or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the udevadm command works in different scenarios.

    $ udevadm
    View All Commands