Bird
Raised Fist0
Linux CLIscripting~20 mins

dmesg for kernel messages in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Kernel Message Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What does this dmesg command output?
You run the command dmesg | grep usb on a Linux system. What kind of output should you expect?
Linux CLI
dmesg | grep usb
ALines containing kernel messages related to USB devices, such as device connection or disconnection events.
BA list of all running processes related to USB devices.
CThe current USB device configuration settings in a table format.
DA summary of all network interfaces and their statuses.
Attempts:
2 left
💡 Hint
Think about what dmesg shows and what grep does when filtering for 'usb'.
🧠 Conceptual
intermediate
2:00remaining
Why use dmesg instead of checking /var/log/messages for kernel logs?
Which reason best explains why you might prefer using dmesg to view kernel messages instead of reading the /var/log/messages file?
Admesg requires root privileges, while /var/log/messages does not.
B/var/log/messages only contains user application logs, not kernel messages.
Cdmesg shows the current kernel ring buffer directly, providing real-time kernel messages without delay.
D/var/log/messages is only updated once per day, so it never shows recent kernel events.
Attempts:
2 left
💡 Hint
Think about how dmesg accesses kernel messages compared to log files.
📝 Syntax
advanced
2:00remaining
Which command correctly shows the last 10 kernel messages using dmesg?
You want to see only the last 10 lines of kernel messages using dmesg. Which command will do this correctly?
Admesg -n 10
Bdmesg tail 10
Cdmesg --last 10
Ddmesg | tail -10
Attempts:
2 left
💡 Hint
Remember that dmesg outputs all messages and you can pipe it to other commands.
🔧 Debug
advanced
2:00remaining
What error occurs with this dmesg command?
You run the command dmesg --follow to watch kernel messages live, but it returns an error. What is the likely cause?
Linux CLI
dmesg --follow
AError: unrecognized option '--follow' because the dmesg version does not support this flag.
BPermission denied error because dmesg requires root to run.
CSyntax error due to missing argument after '--follow'.
DNo error; the command runs and shows live kernel messages.
Attempts:
2 left
💡 Hint
Check if the dmesg version supports the option you used.
🚀 Application
expert
3:00remaining
How to filter dmesg output for kernel warnings and save to a file?
You want to save all kernel warning messages from dmesg to a file named warnings.log. Which command does this correctly?
Admesg --level=warning > warnings.log
Bdmesg | grep -i warning > warnings.log
Cdmesg | filter warning > warnings.log
Ddmesg -w > warnings.log
Attempts:
2 left
💡 Hint
Use grep to filter text output for keywords.

Practice

(1/5)
1. What is the primary purpose of the dmesg command in Linux?
easy
A. To display kernel messages and system events
B. To list all running processes
C. To show disk usage statistics
D. To edit system configuration files

Solution

  1. Step 1: Understand the role of dmesg

    The dmesg command reads the kernel ring buffer, which contains messages about system events and hardware status.
  2. Step 2: Compare with other options

    Options A, B, and C relate to file editing, process listing, and disk usage, which are unrelated to kernel messages.
  3. Final Answer:

    To display kernel messages and system events -> Option A
  4. Quick Check:

    Kernel messages = display with dmesg [OK]
Hint: dmesg always shows kernel logs, not processes or files [OK]
Common Mistakes:
  • Confusing dmesg with ps or top commands
  • Thinking dmesg edits files
  • Assuming dmesg shows disk info
2. Which of the following is the correct syntax to display kernel messages with human-readable timestamps using dmesg?
easy
A. dmesg -r
B. dmesg --time
C. dmesg -T
D. dmesg -h

Solution

  1. Step 1: Identify the option for readable timestamps

    The -T option in dmesg converts kernel timestamps to human-readable format.
  2. Step 2: Verify other options

    -r reverses output order, --time is invalid, and -h shows help.
  3. Final Answer:

    dmesg -T -> Option C
  4. Quick Check:

    Readable time = -T option [OK]
Hint: Use -T for readable timestamps in dmesg output [OK]
Common Mistakes:
  • Using -r instead of -T for timestamps
  • Typing invalid options like --time
  • Confusing -h (help) with timestamp option
3. What will be the output of the command dmesg | grep usb?
medium
A. All kernel messages containing the word 'usb'
B. Only USB device names without any messages
C. A list of all running USB processes
D. An error because grep cannot be used with dmesg

Solution

  1. Step 1: Understand the pipe and grep usage

    The command pipes dmesg output to grep usb, filtering lines containing 'usb'.
  2. Step 2: Interpret the filtered output

    This shows kernel messages related to USB devices or events, not just names or processes.
  3. Final Answer:

    All kernel messages containing the word 'usb' -> Option A
  4. Quick Check:

    dmesg | grep filters messages by keyword [OK]
Hint: Pipe dmesg to grep to filter messages by keyword [OK]
Common Mistakes:
  • Thinking grep lists processes
  • Expecting only device names without messages
  • Assuming grep causes errors with dmesg
4. You run dmesg -T but get an error saying "dmesg: option requires an argument -- 'T'". What is the likely cause?
medium
A. You typed the command incorrectly; -T needs a filename
B. You used an older dmesg version that does not support -T
C. The kernel is not loaded, so dmesg fails
D. You need root permissions to use -T option

Solution

  1. Step 1: Analyze the error message

    The error says the option -T requires an argument, which is unusual because -T normally needs none.
  2. Step 2: Understand version compatibility

    Older versions of dmesg do not support -T, causing this error.
  3. Final Answer:

    You used an older dmesg version that does not support -T -> Option B
  4. Quick Check:

    Old dmesg versions lack -T support [OK]
Hint: Check dmesg version if -T option errors [OK]
Common Mistakes:
  • Assuming -T needs a filename argument
  • Thinking root permission is required for -T
  • Blaming kernel load status for this error
5. You want to monitor new kernel messages related to network devices in real-time. Which command combination is best?
hard
A. dmesg --follow --filter=net
B. dmesg -T | grep net
C. dmesg | tail -n 10 | grep net
D. dmesg -w | grep net

Solution

  1. Step 1: Identify real-time monitoring option

    The -w option makes dmesg wait and show new messages as they appear.
  2. Step 2: Combine with grep for filtering

    Piping to grep net filters messages related to network devices.
  3. Step 3: Evaluate other options

    -T shows timestamps but is not real-time; tail -n 10 shows only last 10 lines; --follow --filter=net is invalid syntax.
  4. Final Answer:

    dmesg -w | grep net -> Option D
  5. Quick Check:

    Real-time dmesg = -w with grep filter [OK]
Hint: Use dmesg -w for live kernel logs, pipe to grep to filter [OK]
Common Mistakes:
  • Using -T for real-time (it only formats time)
  • Using tail only shows past logs, not live
  • Assuming --follow or --filter options exist
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard