Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

Dmesg Command in Linux - DesignLinux

Sep 05 2020
designlinux 0 Comments
Dmesg Command in Linux

The dmesg command-line utility is used to view and control the kernel ring buffer in Linux and other Unix-like operating systems. It is useful for examining kernel boot messages and debugging hardware related issues. In this guide, we will show you the basics of the dmesg command.

In the Linux operating system the Linux kernel is the core that manages the system resources. The kernel writes various messages to the kernel ring buffer during the boot process, and when the system is running. These messages include various information about the operation of the system.

Using the dmesg Command#

The basic syntax for the dmesg command is as following:

dmesg [OPTIONS]

If you run the dmesg without any options it will writes all messages from the kernel ring buffer to the standard output:

dmesg

In some of systems the root level users only can run the dmesg command and in some of system it allows users to run dmesg command. If the user have not permission then following error message will be displayed:

dmesg: read kernel buffer failed: Operation not permitted

You also can manage the restriction that the non-root user can use the dmesg command or not by kernel parameter kernel.dmesg_restrict. You should set it zero to remove the restrictions:

sudo sysctl -w kernel.dmesg_restrict=0

There will many lines in output so the last few lines are viewable on terminal. You can pipe the output with less utility:

dmesg --color=always | less

The --color=always is used to preserve the colored output.

You also can use the grep command to filter the output. For example, to view only the USB related messages, you would type:

dmesg | grep -i usb

dmesg reads the messages generated by the kernel from the /proc/kmsg virtual file. This file provides an interface to the kernel ring buffer and can be opened only by one process. If syslog process is running on your system and you try to read the file with cat , or less, the command will hang.

The syslog daemon dumps kernel messages to /var/log/dmesg, so you can also use that log file:

cat /var/log/dmesg

Formating dmesg Output#

As we seen previously the output of dmesg have the lots of lines. The dmesg command provides number of options that help to format and filter the output.

The -H (--human) is the commonly used option, which show the human readable output.

dmesg -H

To print human-readable timestamps use the -T (--ctime) option:

dmesg -T
[Fri Sep 4 10:20:04 2020] IPv6: ADDRCONF(NETDEV_CHANGE): wlp1s0: link becomes ready

The timestamps format can also be set using the –time-format option, which can be ctime, reltime, delta, notime, or iso. For example to use the delta format you would type:

You also can set the timestamps using the --time-format option. To use delta format, type:

dmesg --time-format=delta

You also can use the two options simultaneously:

dmesg -H -T

To watch the output of the dmesg command in real-time use the -w (--follow) option:

dmesg --follow

Filtering dmesg Output#

The dmesg supports the following log facilities:

  • kern – kernel messages
  • user – user-level messages
  • mail – mail system
  • daemon – system daemons
  • auth – security/authorization messages
  • syslog – internal syslogd messages
  • lpr – line printer subsystem
  • news – network news subsystem

Using the -f (--facility ) option you can limit the output to specific facilities. The option accepts one or more comma-separated facilities.

For example, to display only the kernel and system daemons messages you would use:

dmesg -f kern,daemon

Each log message is associated with a log level that shows the importance of the message. dmesg supports the following log levels:

  • emerg – system is unusable
  • alert – action must be taken immediately
  • crit – critical conditions
  • err – error conditions
  • warn – warning conditions
  • notice – normal but significant condition
  • info – informational
  • debug – debug-level messages

The -l (--level ) option restricts the output to defined levels. The option accepts one or more comma-separated levels.

The following command displays only the error and critical messages:

dmesg -l err,crit

Clearing the Ring Buffer#

Option -C (--clear) allows you to clear the ring buffer:

sudo dmesg -C

Make sure to clear the ring buffer you should logged in as root or user with sudo privileges.

To print the buffer contents before clearing use the -c (--read-clear) option:

sudo dmesg -c

If you want to save the current dmesg logs in a file before clearing it, redirect the output to a file:

dmesg > dmesg_messages

Conclusion#

The dmesg command allows you to view and control the kernel ring buffer. Type man dmesg in your terminal for information about all available dmesg options.

If you have any questions or feedback, feel free to leave a comment.

Related

Tags: dmesg, kernel, terminal

How to Setup Automatic Kernel Updates on Linux

Prev Post

How to Install Chromium Web Browser on Ubuntu 20.04

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 0
  • 580
  • 1,055,352

DesignLinux.com © All rights reserved

Go to mobile version