目錄
Viewing Kernel Messages
Filtering Output for Specific Information
Clearing or Controlling the Ring Buffer (Use with Caution)
首頁 系統教程 Linux DMESG命令是用什麼?

DMESG命令是用什麼?

Jul 23, 2025 am 12:01 AM
linux dmesg命令

dmesg用於查看和控制內核環形緩衝區,其核心功能包括:1. 顯示內核消息;2. 過濾特定信息;3. 清除或控制緩衝區。默認運行dmesg將輸出所有內核消息,適用於排查硬件問題及啟動過程分析,可通過管道結合less分頁查看或使用--level參數篩選錯誤級別信息。用戶還可利用grep按關鍵詞過濾如USB、磁盤I/O錯誤等,並通過-T選項添加時間戳以輔助日誌關聯。在必要時,可使用-dmesg -C清除消息緩衝區,-D和-E禁用或啟用控制台日誌記錄,但需謹慎操作以免影響後續故障診斷。

What is the dmesg command used for?

The dmesg command is used to view and control the kernel ring buffer, which stores messages generated by the Linux kernel. These messages include system startup information, hardware detection, driver loading, and various runtime events — both normal and error-related.

Viewing Kernel Messages

By default, running dmesg without any arguments will print all the messages from the kernel ring buffer to the terminal. This can be especially useful when troubleshooting hardware issues or understanding what happened during boot-up.

For example:

 dmesg

You'll see a long list of messages that might look cryptic at first, but they contain valuable details like detected devices, memory allocation, and errors.

If the output is too much to read at once, you can pipe it into a pager:

 dmesg | less

Or filter specific types of messages, such as those related to errors or warnings:

 dmesg --level=err,warn

This helps narrow down problems quickly without scanning through thousands of lines.

Filtering Output for Specific Information

Since the full output of dmesg can be overwhelming, filtering is key. You can use tools like grep to search for specific keywords such as disk names ( sda , nvme0n1 ), drivers, or error codes.

Examples:

  • Check for USB-related messages:
     dmesg | grep usb
  • Look for disk I/O errors:
     dmesg | grep -i "i/o"
  • See if a particular module loaded correctly:
     dmesg | grep nouveau

These filters help isolate relevant logs, especially when debugging hardware or driver issues.

Also, timestamps are often useful. Adding the -T option shows human-readable timestamps next to each message:

 dmesg -T

This makes it easier to correlate kernel events with other logs or user-reported issues.

Clearing or Controlling the Ring Buffer (Use with Caution)

Although not commonly needed, dmesg allows you to clear the kernel log buffer using:

 dmesg -C

This clears all existing messages. It's usually only done in specific diagnostic scenarios or automated testing.

There's also an option to disable and re-enable the logging of messages to the console:

  • Disable: dmesg -D
  • Enable: dmesg -E

These options are rarely used outside of server maintenance or embedded systems work.

⚠️ Keep in mind: clearing logs can make troubleshooting harder later, so do this only when necessary and understand the consequences.


That's basically how most users interact with dmesg . It's a simple tool but incredibly powerful when you're trying to figure out what the kernel knows — especially when things aren't working quite right.

以上是DMESG命令是用什麼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

PHP教程
1596
276
如何讓PHP容器支持自動構建 PHP環境持續集成CI配置方式 如何讓PHP容器支持自動構建 PHP環境持續集成CI配置方式 Jul 25, 2025 pm 08:54 PM

要讓PHP容器支持自動構建,核心在於配置持續集成(CI)流程。 1.使用Dockerfile定義PHP環境,包括基礎鏡像、擴展安裝、依賴管理和權限設置;2.配置GitLabCI等CI/CD工具,通過.gitlab-ci.yml文件定義build、test和deploy階段,實現自動構建、測試和部署;3.集成PHPUnit等測試框架,確保代碼變更後自動運行測試;4.使用Kubernetes等自動化部署策略,通過deployment.yaml文件定義部署配置;5.優化Dockerfile,採用多階段構

Linux vs Windows:哪個操作系統更適合您? Linux vs Windows:哪個操作系統更適合您? Jul 29, 2025 am 03:40 AM

Windowsisbetterforbeginnersduetoeaseofuse,seamlesshardwarecompatibility,andsupportformainstreamsoftwarelikeMicrosoftOfficeandAdobeapps.2.LinuxoutperformsWindowsonolderorlow-resourcehardwarewithfasterboottimes,lowersystemrequirements,andlessbloat.3.Li

如何搭建獨立PHP任務容器環境 PHP定時腳本運行容器配置方法 如何搭建獨立PHP任務容器環境 PHP定時腳本運行容器配置方法 Jul 25, 2025 pm 07:27 PM

搭建獨立PHP任務容器環境可通過Docker實現,具體步驟如下:1.安裝Docker與DockerCompose作為基礎;2.創建獨立目錄存放Dockerfile、crontab文件;3.編寫Dockerfile定義PHPCLI環境並安裝cron及必要擴展;4.編寫crontab文件定義定時任務;5.編寫docker-compose.yml掛載腳本目錄並配置環境變量;6.啟動容器並驗證日誌。相比Web容器內執行定時任務,獨立容器具備資源隔離、環境純粹、穩定性強、便於擴展等優勢。為確保日誌與錯誤捕

如何使用終端在Linux上安裝軟件? 如何使用終端在Linux上安裝軟件? Aug 02, 2025 pm 12:58 PM

在Linux上安裝軟件主要有三種方法:1.使用包管理器,如apt、dnf或pacman,通過更新源後執行install命令安裝,例如sudoaptinstallcurl;2.對於.deb或.rpm文件,分別使用dpkg或rpm命令安裝,並在需要時修復依賴;3.使用snap或flatpak跨平台安裝應用,如sudosnapinstall軟件名,適用於追求版本更新的用戶,推薦優先使用系統自帶包管理器以獲得更好的兼容性和性能。

如何使用Cron和Anacron在Linux上安排任務 如何使用Cron和Anacron在Linux上安排任務 Aug 01, 2025 am 06:11 AM

cronisusedforpreciseschedulingonalways-onsystems,whileanacronensuresperiodictasksrunonsystemsthataren'tcontinuouslypowered,suchaslaptops;1.Usecronforexacttiming(e.g.,3AMdaily)viacrontab-ewithsyntaxMINHOURDOMMONDOWCOMMAND;2.Useanacronfordaily,weekly,o

Linux上高性能遊戲的最終指南 Linux上高性能遊戲的最終指南 Aug 03, 2025 am 05:51 AM

ChoosePop!_OS,Ubuntu,NobaraLinux,orArchLinuxforoptimalgamingperformancewithminimaloverhead.2.InstallofficialNVIDIAproprietarydriversforNVIDIAGPUs,ensureup-to-dateMesaandkernelversionsforAMDandIntelGPUs.3.EnabletheperformanceCPUgovernor,usealow-latenc

Linux與Windows的主要利弊是什麼? Linux與Windows的主要利弊是什麼? Aug 03, 2025 am 02:56 AM

Linux適合老舊硬件、安全性高、可定制,但軟件兼容性弱;Windows軟件豐富、易用,但資源佔用高。 1.性能上,Linux輕量高效,適合舊設備;Windows對硬件要求高。 2.軟件上,Windows兼容性更廣,尤其專業工具和遊戲;Linux需借助工具運行部分軟件。 3.安全上,Linux權限管理更嚴格,更新便捷;Windows雖有防護但仍易受攻擊。 4.使用難度上,Linux學習曲線陡峭;Windows操作直觀。根據需求選擇:重性能與安全選Linux,重兼容與易用選Windows。

時間同步在Linux上與NTP的重要性 時間同步在Linux上與NTP的重要性 Aug 01, 2025 am 06:00 AM

timessynchronizationiscroucialforsystemriabilitile andsecurityBecurityBecurityBecurityTimecauseslogConfusion,SecurityFailures,不正確的SCHEDULEDTASKS,and distributedSystementerors; 1.CheckntpStatusptatususistimeDimeDimeDatectlstatectlstatustatustoconFirmSynChronChronChronChronizationServiciative and servicivity; 2

See all articles