dmesg Command in Linux
Build an AI-First Career, Master the Complete Skillset
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
AI Forward Deployed Engineer Program
Full-stack engineering, production AI and client-facing consulting
+1000 moreOverview
In the heart of every Linux system, the kernel is constantly interacting with hardware, processes, and system services. A crucial tool for understanding these interactions is the dmesg command in Linux. It allows users to peek into the kernel's activities by displaying its message buffer, often used for troubleshooting hardware issues and system errors.
Syntax of dmesg Command in Linux
The basic syntax of the dmesg command in Linux is as follows:
Where:
- dmesg: This is the command itself, which triggers the display of the kernel's message buffer.
- [options]: This is where you specify options that modify the behavior of the command. These options are optional and can be combined as needed.
Options in dmesg command in Linux
-
-C, --clear: Clears the kernel ring buffer.
For example -
This command does not produce any output as it's used to clear the kernel ring buffer. It requires root privileges.
-
-w, --follow: Displays the messages in real-time as they appear in the kernel ring buffer.
For example -
This command does not produce any output initially. Instead, it will keep the terminal open and print new kernel messages as they occur.
-
-T, --ctime: Print human-readable timestamps.
For example -
Output:
This command prints the kernel messages with human-readable timestamps instead of the default time since the system boot.
How Scaler Transformed Careers in Different Fields
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Example Usages
-
Displaying the kernel messages.:
Output:
Explanation: This command displays the kernel messages. The numbers in the brackets are the timestamp, showing time since the system booted.
-
Filtering kernel messages by a specific facility like 'memory'.:
Output:
Explanation: This command filters the kernel messages to only show those related to memory.
Tips
-
The dmesg command requires root privileges to access some of the functionalities. Consider using 'sudo' when appropriate.
-
The output of dmesg can be quite extensive. It's often helpful to pipe the output to 'less' or 'grep' to filter and navigate through the messages.
Turn Learning into Career Growth
Advanced Use Cases of dmesg Command in Linux
-
Using the --level option to filter messages by priority.:
Output:
Explanation: This command displays only the error and warning messages from the kernel ring buffer. The --level option can take different values like emerg, alert, crit, err, warn, notice, info, and debug.
-
Displaying the kernel messages related to a specific device like 'eth0'.:
Output:
Explanation: This command filters the kernel messages to only show those related to the 'eth0' network interface.
-
Saving the kernel messages to a file.:
Explanation: This command does not produce any output on the terminal. Instead, it saves the kernel messages to a file named 'kernel_messages.log'.
Conclusion
-
The dmesg command in Linux is a powerful tool for viewing and understanding the activities of the Linux kernel.
-
It's most commonly used for troubleshooting hardware issues and system errors.
-
The output of dmesg can be filtered using various options and by piping it to other commands like 'grep'.
-
Some functionalities of dmesg require root privileges.