Skip to content

Linux lsmod command

The Linux lsmod command is used to display information about loaded kernel modules. It provides details such as the module name, size, and the number of instances of each module currently loaded in the kernel. This command helps users to easily see which modules are currently loaded and can be useful for troubleshooting or monitoring system resources. By using the lsmod command, users can get an overview of the kernel modules that are being utilized by the system.

Kernel modules are pieces of code that can be loaded and unloaded into the kernel without rebooting the system. These modules can add functionality to the kernel, such as device drivers or file systems. The lsmod command reads the /proc/modules file to gather information about the currently loaded modules. It is a straightforward and efficient way to check the status of kernel modules on a Linux system.

lsmod Syntax:

Terminal window
lsmod [options]

Options:

OptionDescription
-aDisplay all modules
-vDisplay detailed information
-hDisplay help message

Parameters:

ParameterDescription
Noneno additional parameters

lsmod Usage:

List Loaded Kernel Modules

Terminal window
lsmod

Displays a list of all currently loaded kernel modules.

Filter lsmod Output by Module Name

Terminal window
lsmod | grep <module_name>

Filters the lsmod output to display information about a specific kernel module.

List Loaded Kernel Modules with Details

Terminal window
lsmod -l

Displays a detailed list of all loaded kernel modules, including information like size and dependencies.

Sort lsmod Output by Module Size

Terminal window
lsmod | sort -k2

Sorts the lsmod output by module size, displaying the largest modules at the bottom for easy identification.

How do I use lsmod in Linux?

To use the lsmod command in Linux, execute the following command:

Terminal window
lsmod

What flag can I use with lsmod to display module size information?

To display module size information along with the loaded modules, use the ‘-s’ or ‘—size’ flag.

Terminal window
lsmod -s

How can I show the usage count for each module with lsmod?

To display the usage count for each loaded module, you can use the ‘-u’ or ‘—used’ flag.

Terminal window
lsmod -u

How do I list modules by specific keywords with lsmod?

To list only the modules containing specific keywords, you can use the grep command in combination with lsmod.

Terminal window
lsmod | grep <keyword>

How can I display the module dependencies using lsmod?

To view the dependencies between loaded modules, you can use the ‘modprobe’ command with the ‘-D’ or ‘—show-depends’ flag.

Terminal window
modprobe -D <module_name>

How can I get detailed information about a specific module using lsmod?

To get detailed information about a specific module, you can use the ‘modinfo’ command followed by the module name.

Terminal window
modinfo <module_name>

How can I force the removal of a module in use with lsmod?

To forcefully remove a module that is in use, you can use the ‘rmmod’ command followed by the module name.

Terminal window
rmmod <module_name>

Applications of the lsmod command

  • Listing currently loaded kernel modules
  • Checking the status of kernel modules
  • Troubleshooting driver issues
  • Identifying kernel modules that are affecting system performance
  • Monitoring kernel module dependencies