Bird
Raised Fist0
Linux CLIscripting~10 mins

System resource monitoring (free, uptime, vmstat) in Linux CLI - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - System resource monitoring (free, uptime, vmstat)
Run 'free' command
↓
Display memory usage
↓
Run 'uptime' command
↓
Show system uptime and load
↓
Run 'vmstat' command
↓
Show CPU, memory, IO stats
↓
End of monitoring snapshot
The flow shows running three commands one after another to get memory, uptime, and system stats snapshots.
Execution Sample
Linux CLI
free
uptime
vmstat 1 2
Runs free to show memory, uptime for system time/load, vmstat for CPU/memory stats twice with 1 second interval.
Execution Table
StepCommandOutput SummaryDetails
1freeShows total, used, free memory and swapMem: total=8000MB, used=3000MB, free=5000MB; Swap: total=2000MB, used=0MB, free=2000MB
2uptimeShows system uptime and load averagesUptime=5 days 3:20, Load averages=0.15, 0.10, 0.05
3vmstat 1 2 (first)First vmstat snapshotr=1, b=0, swpd=0, free=5000, buff=200, cache=1000, si=0, so=0, bi=10, bo=5, in=100, cs=200, us=5, sy=3, id=90, wa=2, st=0
4vmstat 1 2 (second)Second vmstat snapshot after 1 secondr=0, b=0, swpd=0, free=4800, buff=250, cache=1100, si=0, so=0, bi=5, bo=3, in=90, cs=180, us=3, sy=2, id=95, wa=0, st=0
5EndMonitoring snapshot completeAll commands executed, system stats captured
💡 All commands completed, system resource snapshot taken
Variable Tracker
VariableStartAfter freeAfter uptimeAfter vmstat 1After vmstat 2Final
Memory Used (MB)unknown30003000300030003000
Memory Free (MB)unknown50005000500048004800
System Uptimeunknownunknown5 days 3:205 days 3:205 days 3:205 days 3:20
CPU Usage User (%)unknownunknownunknown533
CPU Idle (%)unknownunknownunknown909595
Key Moments - 3 Insights
Why does vmstat show two sets of data when we run 'vmstat 1 2'?
The first vmstat output shows stats since last reboot, the second is the real snapshot after 1 second interval (see rows 3 and 4 in execution_table).
What does the 'load average' in uptime mean?
Load average shows average system demand over 1, 5, and 15 minutes, indicating how busy the CPU is (see row 2 in execution_table).
Why is free memory different between free and vmstat outputs?
free shows memory including buffers/cache, vmstat separates free memory and buffers/cache (see variable_tracker Memory Free values).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table row 2, what is the system uptime shown by 'uptime'?
A5 hours 3 minutes
B5 days 3:20
C3 days 5:20
DUnknown
💡 Hint
Check the 'Output Summary' and 'Details' columns in execution_table row 2.
At which vmstat snapshot does CPU idle percentage increase?
ASecond snapshot
BFirst snapshot
CBoth snapshots are equal
DCPU idle is not shown
💡 Hint
Compare 'CPU Idle (%)' in variable_tracker after vmstat 1 and vmstat 2.
If the system had more swap used, which command output would show it clearly?
Avmstat
Buptime
Cfree
DNone of these
💡 Hint
Look at the 'free' command output in execution_table row 1 showing swap usage.
Concept Snapshot
System resource monitoring uses commands:
- free: shows memory and swap usage
- uptime: shows system running time and load averages
- vmstat: shows CPU, memory, IO stats in intervals
Run them sequentially for a snapshot of system health.
Full Transcript
This visual execution shows how to monitor system resources on Linux using three commands: free, uptime, and vmstat. First, 'free' displays memory and swap usage, telling how much RAM is used and free. Next, 'uptime' shows how long the system has been running and the load averages, which indicate CPU demand. Finally, 'vmstat' gives detailed CPU, memory, and IO statistics, showing two snapshots with a 1-second gap. The execution table traces each command's output step-by-step, and the variable tracker follows key values like memory used, free memory, uptime, and CPU usage. Key moments clarify common confusions like why vmstat shows two outputs and what load averages mean. The quiz tests understanding by asking about uptime, CPU idle changes, and swap usage visibility. This helps beginners see how these commands work together to give a clear picture of system health.

Practice

(1/5)
1. What does the free command primarily display on a Linux system?
easy
A. System uptime and load average
B. Disk usage statistics
C. CPU temperature
D. Memory usage and availability

Solution

  1. Step 1: Understand the purpose of free

    The free command shows information about the system's memory usage, including total, used, free, and available memory.
  2. Step 2: Compare with other commands

    uptime shows system running time and load, vmstat shows detailed CPU and memory stats, but free focuses on memory.
  3. Final Answer:

    Memory usage and availability -> Option D
  4. Quick Check:

    free = Memory info [OK]
Hint: Remember: free = memory info, uptime = running time [OK]
Common Mistakes:
  • Confusing free with uptime output
  • Thinking free shows CPU or disk info
  • Mixing vmstat details with free
2. Which of the following is the correct syntax to display memory usage in megabytes using the free command?
easy
A. free -k
B. free -m
C. free -g
D. free --bytes

Solution

  1. Step 1: Identify the option for megabytes

    The -m option in free shows memory in megabytes.
  2. Step 2: Check other options

    --bytes shows bytes, -g shows gigabytes, -k shows kilobytes. So -m is correct for MB.
  3. Final Answer:

    free -m -> Option B
  4. Quick Check:

    free -m = megabytes [OK]
Hint: Use -m for MB, -k for KB, -g for GB in free [OK]
Common Mistakes:
  • Using -k expecting MB output
  • Confusing --bytes with -m
  • Using wrong option like -g for MB
3. What output will the command uptime produce on a system that has been running for 3 days, 4 hours, 12 minutes with load averages 0.15, 0.10, 0.05?
medium
A. 10:30:00 up 3 days, 4:12, 1 user, load average: 0.15, 0.10, 0.05
B. 3 days, 4 hours, 12 minutes uptime with load 0.15, 0.10, 0.05
C. uptime: 3d 4h 12m, load: 0.15 0.10 0.05
D. System up for 3 days 4 hours 12 minutes, load averages: 0.15 0.10 0.05

Solution

  1. Step 1: Understand uptime output format

    The uptime command shows current time, system uptime in days and hours:minutes, number of users, and load averages.
  2. Step 2: Match given data to output style

    The correct format includes current time, "up 3 days, 4:12", user count, and load averages separated by commas.
  3. Final Answer:

    10:30:00 up 3 days, 4:12, 1 user, load average: 0.15, 0.10, 0.05 -> Option A
  4. Quick Check:

    uptime shows time, up, users, load [OK]
Hint: Look for 'up' and load averages format in uptime output [OK]
Common Mistakes:
  • Expecting uptime to print in verbose sentences
  • Missing commas or user count in output
  • Confusing uptime with other commands
4. You run vmstat 1 3 but get an error saying "command not found". What is the most likely cause?
medium
A. vmstat is not installed on the system
B. The interval must be greater than 1 second
C. The command syntax is incorrect; count must be last
D. You need to run vmstat as root user

Solution

  1. Step 1: Verify vmstat syntax

    vmstat 1 3 uses correct syntax: 1-second delay, 3 samples.
  2. Step 2: Analyze the error

    "command not found" means vmstat (from procps package) is not installed.
  3. Final Answer:

    vmstat is not installed on the system -> Option A
  4. Quick Check:

    command not found = not installed [OK]
Hint: vmstat missing? Install procps package [OK]
Common Mistakes:
  • Assuming syntax error for missing command
  • Thinking root needed for vmstat
  • Believing interval too small
5. You want to monitor CPU and memory usage every 2 seconds for 5 samples using vmstat. Which command will correctly do this and what will be the total monitoring time?
hard
A. vmstat 2 5; total time 10 seconds
B. vmstat 5 2; total time 10 seconds
C. vmstat 2 5; total time 8 seconds
D. vmstat 5 2; total time 8 seconds

Solution

  1. Step 1: Understand vmstat interval and count

    vmstat 2 5 runs vmstat every 2 seconds, 5 times total.
  2. Step 2: Calculate total monitoring time

    vmstat prints the first line immediately, then 4 intervals of 2 seconds each, so total time = 2 * (5 - 1) = 8 seconds.
  3. Final Answer:

    vmstat 2 5; total time 8 seconds -> Option C
  4. Quick Check:

    Total time = interval * (count - 1) [OK]
Hint: Total time = interval x (count - 1) for vmstat [OK]
Common Mistakes:
  • Multiplying interval by count instead of count-1
  • Swapping interval and count values
  • Assuming total time equals interval x count
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