Linux Commands - System statistic commands

Reference Linux

Following are some of the important system statistic commands in Linux.

free -h

This command displays the amount of free and used memory in the system.

In the following example we are getting the free and used memory.

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           1.9G        933M        208M         10M        851M        880M
Swap:          1.4G        780K        1.4G

df -h

This command reports the file system disk space usage.

In the following example we are getting the disk space usage.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            969M     0  969M   0% /dev
tmpfs           200M  1.5M  198M   1% /run
/dev/sda1        30G  6.0G   22G  22% /
...
...
...

iostat

This command reports the CPU (Central Processing Unit) statistics and I/O (input/output) statistics for devices and partitions.

In the following example we are getting the IO stats.

$ iostat
Linux 4.15.0-20-generic (yusufshakeel-ubuntu)  Monday 01 January 2018        _x86_64_        (1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           3.32    0.59    0.94    0.17    0.00   94.98

Device             tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
loop0             0.02         0.42         0.00       1048          0
loop1             3.68         4.09         0.00      10150          0
loop2             0.02         0.14         0.00        348          0
loop3             0.02         0.05         0.00        116          0
loop4             0.02         0.14         0.00        347          0
loop5             0.04         0.45         0.00       1114          0
loop6             0.02         0.05         0.00        120          0
loop7             0.02         0.14         0.00        350          0
scd0              0.02         0.07         0.00        186          0
sda              12.28       313.30       134.68     778389     334612
loop8             0.02         0.04         0.00        110          0
loop9             0.02         0.14         0.00        350          0
loop10            0.03         0.44         0.00       1082          0
loop11            3.03         3.15         0.00       7824          0
loop12            0.16         0.27         0.00        678          0
loop13            0.04         0.07         0.00        171          0
loop14            0.02         0.05         0.00        115          0
loop15            0.00         0.00         0.00          1          0

iostat -d 2

This will display a continuous device report at an interval of 2 seconds.

$ iostat -d 2

To break out of the continuous report press Ctrl+C.

vmstat

This command will report the virtual memory statistics.

In the following example we are getting the virtual memory stats.

$ vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0    780 138884  85884 801708    0    0   245   103   89  374  3  1 96  0  0

mpstat

This command will display the process related statistics.

In the following example we are printing the processor related stats.

$ mpstat
Linux 4.15.0-20-generic (yusufshakeel-ubuntu)  Monday 01 January 2018        _x86_64_        (1 CPU)

08:17:48  IST  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
08:17:48  IST  all    2.96    0.41    0.72    0.12    0.00    0.03    0.00    0.00    0.00   95.75

tail -n N /var/log/syslog

This command will print the last N lines of the system log file.

In the following example we are printing the last 5 lines of the system log file.

$ tail -n 5 /var/log/syslog
Jan  9 08:22:26 yusufshakeel-ubuntu systemd[1]: Started Network Manager Script Dispatcher Service.
Jan  9 08:22:26 yusufshakeel-ubuntu nm-dispatcher: req:1 'connectivity-change': new request (1 scripts)
Jan  9 08:22:26 yusufshakeel-ubuntu nm-dispatcher: req:1 'connectivity-change': start running ordered scripts...
Jan  9 08:22:27 yusufshakeel-ubuntu whoopsie[662]: [08:22:27] online
Jan  9 08:45:02 yusufshakeel-ubuntu CRON[4228]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT