Guides

dmesg command: read kernel messages, readable timestamps, follow and filter

How to use the dmesg command on Linux: -H and -T timestamps, -w to follow, --level filters, grep for disk, OOM and segfault lines, and the permission error.

Published ~8 min read
On this page

Short answer: dmesg prints the kernel's message buffer: hardware detection at boot, driver messages, disk and filesystem errors, OOM kills and crashing programs. On most servers you need sudo; add -T for readable times, -w to follow new messages and --level=err,warn to see only problems.

Linux
sudo dmesg -H                      # readable, coloured, opens in a pager
sudo dmesg -T | tail -n 50         # last 50 lines with wall-clock times
sudo dmesg -w                      # follow new messages, Ctrl+C to stop
sudo dmesg --level=err,warn        # errors and warnings only
sudo dmesg -T | grep -i 'i/o error'

dmesg is part of util-linux. Debian 12 ships 2.38.1, Ubuntu 24.04 ships 2.39.3 and Debian 13 ships 2.41; the options below exist in all three unless a version is named. On our Debian 12 host we ran only dmesg --help, --version and the level filters against a sample file (-F); the kernel lines in this article are written from the kernel's own message formats, not copied from a real server.

The dmesg options you will use

OptionWhat it doesNote
-HHuman-readable output: relative times, colour, pager-P turns the pager off
-TWall-clock timestamps instead of seconds since bootCan be wrong after suspend, see below
--time-format isoISO 8601 timestampsBest for comparing two machines
-wWait for new messages and print them-W prints only the new ones
-l err,warnOnly the named levels--level; err+ needs 2.39 or later
-f kernOnly the named facilities--facility
-kKernel messages only (facility kern)-u: userspace messages only
-xPrefix every line with facility and levelShows why a line matched a filter
--since '1 hour ago'Only messages after a timeAlso --until; same accuracy caveat as -T
-JJSON outputFor scripts
-CClear the bufferNeeds root; -c prints first, then clears

Timestamps: -T, -e and why -T can be wrong

Without options each line starts with the kernel's own timestamp in seconds since boot, such as [ 10.500000]. -T converts it to a date, and the util-linux manual warns that the result can be inaccurate: the time source used for the log is not updated after a suspend and resume, and dmesg adjusts the timestamps by the current difference between the boot-time and monotonic clocks, which works only for messages printed after the last resume. Lines from before that resume can show the wrong time. Servers rarely suspend, laptops and desktops often do.

  • -e (--reltime) prints local time plus the gap to the previous line; -d adds just the gap, handy for seeing how long a boot step took.
  • --time-format iso gives YYYY-MM-DDTHH:MM:SS,microseconds+offset, the easiest form to line up with an application log.
  • When the exact time matters, read the same messages through the journal, which records the wall-clock time at which each message reached it (below).

Filter by level and facility

Every kernel message has a level from emerg down to debug: emerg, alert, crit, err, warn, notice, info, debug. --level takes a comma-separated list. We wrote four lines with different levels into a sample file and filtered it:

Example output · dmesg -F sample.log, util-linux 2.38.1
$ dmesg -F sample.log -x
kern  :info  : [    5.120000] example: an info line
kern  :err   : [   10.500000] example: an error line
kern  :warn  : [   12.000000] example: a warning line
kern  :crit  : [   20.000000] example: a critical line

$ dmesg -F sample.log --level=err,warn
[   10.500000] example: an error line
[   12.000000] example: a warning line

$ dmesg -F sample.log --level=err+
dmesg: unknown level 'err+'

The list is exact: err,warn does not include crit. util-linux 2.39 added ranges, so on Ubuntu 24.04 and Debian 13 --level=err+ means err and everything more severe, and +err means err and everything less severe. On Debian 12 write the list out: --level=emerg,alert,crit,err.

--facility filters by origin. Almost everything in the buffer is kern; lines that userspace programs wrote to /dev/kmsg carry other facilities, and -u shows only those.

Follow new messages with -w

Linux
sudo dmesg -wT                                   # everything, as it arrives
sudo dmesg -W | grep --line-buffered -i usb       # only new lines, filtered

Run it in a second terminal while you plug in a disk, load a module or reproduce a crash. -w first prints the existing buffer and then waits; -W skips the backlog. The manual notes that following needs a readable /dev/kmsg (kernel 3.5 and later). --line-buffered matters once grep's output goes into another pipe or a file, such as | tee usb.log; without it grep holds lines back until its buffer fills.

What to grep for: disks, memory, crashes and network

Linux
sudo dmesg -T | grep -iE 'i/o error|critical medium|ext4-fs error|xfs.*error|btrfs.*error|remounting'
sudo dmesg -T | grep -iE 'out of memory|oom-killer|killed process'
sudo dmesg -T | grep -i 'segfault'
sudo dmesg -T | grep -iE 'link is (up|down)|nf_conntrack: table full'

This is what the matching lines look like. They follow the format strings in the current kernel source; device names, numbers and the process are placeholders, and ... marks shortened parts:

Illustrative kernel lines, not from a real system
I/O error, dev sdb, sector 123456 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
EXT4-fs error (device sdb1): ...
EXT4-fs (sdb1): Remounting filesystem read-only
example-app invoked oom-killer: gfp_mask=..., order=0, oom_score_adj=0
Out of memory: Killed process 4242 (example-app) total-vm:...kB, anon-rss:...kB, ...
example-app[4242]: segfault at 0 ip ... sp ... error 4 in example-app[...]
nf_conntrack: table full, dropping packet
  • Disk and filesystem. Repeated I/O error lines for one device point at the disk, its cable or controller, or on a VPS the storage behind the virtual disk. A remount to read-only follows filesystem errors; the read-only file system guide walks through what to do next.
  • Memory. invoked oom-killer names the process that asked for memory, Killed process the one that died; the OOM guide explains why they differ and how to stop it.
  • Crashes. A segfault line names the program, its PID and the library or binary it crashed in. On x86, kernels since 6.1 append likely on CPU N (core N, socket N), useful when the same core keeps showing up on a dedicated server with suspect hardware.
  • Network. Link messages depend on the driver; the kernel's common PHY code and drivers such as e1000e print Link is Up and Link is Down, while a virtual network card on a VPS often prints none. nf_conntrack: table full means the firewall's connection table is full and new connections are being dropped.

A critical medium error line (same format as the I/O error, different first words) means the drive itself reported a media error, such as a sector it cannot read: read the disk's own health data next. On a dedicated server with ECC memory, also grep for EDAC: its lines count corrected (CE) and uncorrected (UE) memory errors; see what ECC memory is for what those counts mean.

dmesg: read kernel buffer failed: Operation not permitted

As a normal user on Debian 12 we got exactly this, with exit code 1:

Example output · dmesg as an unprivileged user, Debian 12
dmesg: read kernel buffer failed: Operation not permitted

The cause is the sysctl kernel.dmesg_restrict. The kernel documentation says that with 0 there are no restrictions, and with 1 users need the CAP_SYSLOG capability, which in practice means root. The default comes from the kernel build option CONFIG_SECURITY_DMESG_RESTRICT, which Debian's kernel sets, so Debian starts with 1. Check yours with sysctl kernel.dmesg_restrict. Your options:

  • Use sudo dmesg. This is the normal answer on a server.
  • Read the same messages with journalctl -k. The journalctl manual grants members of the systemd-journal and adm groups read access to the whole system journal, so sudo usermod -aG systemd-journal USER lets that user read kernel messages without full sudo after the next login.
  • Turn the restriction off with echo 'kernel.dmesg_restrict = 0' | sudo tee /etc/sysctl.d/90-dmesg.conf and sudo sysctl --system. Every local account can then read the kernel log, so leave it on for servers that other people log in to.

dmesg vs journalctl -k

dmesg reads the kernel ring buffer, which lives in memory. It has a fixed size (at least 128 KiB with Debian 12's kernel build, adjustable with the log_buf_len= boot parameter), old lines are overwritten once it is full, and it starts empty at every boot. systemd-journald copies kernel messages into the journal as they arrive, and journalctl -k shows them:

Linux
journalctl -k                    # kernel messages of this boot
journalctl -k -b -1              # the previous boot, if the journal is persistent
journalctl -k -p err             # level err and more severe
journalctl -k --since '10 min ago' -f

On a VPS, dmesg shows the guest kernel's view: virtual disks and network cards and the guest's own memory, never the host's hardware. A dedicated server shows the real controllers, disks and memory, which makes the disk, EDAC and segfault lines above worth checking after any unexplained hang. For capacity rather than errors, check disk usage first.

Frequently asked

How do I show dmesg with human-readable timestamps?

Run sudo dmesg -T to print a date and time on every line, or sudo dmesg -H for relative times with colour in a pager. The util-linux manual warns that -T can be inaccurate after a suspend and resume, so on a laptop compare the time with journalctl -k.

Why does dmesg say read kernel buffer failed: Operation not permitted?

The sysctl kernel.dmesg_restrict is set to 1, so only processes with the CAP_SYSLOG capability, in practice root, may read the kernel log. Run sudo dmesg, or read the same messages with journalctl -k as a member of the systemd-journal or adm group.

How do I watch dmesg live?

Run sudo dmesg -w to print the buffer and then wait for new messages, or sudo dmesg -W to print only new ones. Stop it with Ctrl+C. To filter, pipe it into grep --line-buffered with your pattern.

What is the difference between dmesg and journalctl -k?

dmesg reads the kernel ring buffer in memory, which has a fixed size and starts empty at every boot. journalctl -k shows the kernel messages that systemd-journald stored, and with a persistent journal journalctl -k -b -1 still shows the messages from before the last reboot.

Related articles

All guides