loading...

Get complete system info using shell commands

bhupesh profile image Bhupesh Varshney ๐Ÿ‘พ Originally published at bhupesh-v.github.io on ใƒป2 min read

Below are a bunch of easy one-liner commands that give information about various aspects of your Linux machine.

Memory Used/Total

free -h | awk '/^Mem:/ {print $3 "/" $2}'
Enter fullscreen mode Exit fullscreen mode

Show CPU temperature

sensors | awk '/^Core*/ {print $1$2, $3}'
Enter fullscreen mode Exit fullscreen mode

Most Memory Intensive processes

ps axch -o cmd:15,%mem --sort=-%mem | head
Enter fullscreen mode Exit fullscreen mode

Most CPU Intensive processes

ps axch -o cmd:15,%cpu --sort=-%cpu | head
Enter fullscreen mode Exit fullscreen mode

I wrote a small shell script to get (almost) realtime update of your system.

#!/usr/bin/env bash

# Realtime system info
#
# Use: watch -ct -n0 sys.sh
# 
# TODO:
# 1. Netspeed 
# 2. Open ports ?


# color definitions
RESET=$'\e[0m'
BOLD_GREEN_FG=$'\e[1;32m'
BOLD_WHITE_FG=$'\e[1m'

## RAM Usage
ram=$(free -h | awk '/^Mem:/ {print $3 "/" $2}')

## Show CPU temperature
temperature=$(sensors | awk '/^Core*/ {print $1$2, $3}')

## Most Memory Intensive processes
mem_intensive=$(ps axch -o cmd:15,%mem --sort=-%mem | head)

## Most CPU Intensive processes
cpu_intensive=$(ps axch -o cmd:15,%cpu --sort=-%cpu | head)


pc_uptime=$(uptime -p | awk '{for (i=2; i<NF; i++) printf $i " "; if (NF >= 1) print $NF; }')

printf "%70s\n\n" "${BOLD_WHITE_FG}System Monitor${RESET}"

printf "\n%s\n" "${BOLD_GREEN_FG}RAM :${RESET} $ram"

printf "\n%s\n\n" "${BOLD_GREEN_FG}CPU Temperature ๐ŸŒก : ${RESET}"
printf "%s\n" "$temperature"

printf "\n%s\n\n" "${BOLD_GREEN_FG}Most Memory Intensive Processes${RESET}"
printf "%s" "$mem_intensive"

printf "\n\n%s\n\n" "${BOLD_GREEN_FG}Most CPU Intensive Processes${RESET}"
printf "%s\n\n" "$cpu_intensive"
Enter fullscreen mode Exit fullscreen mode

Here is a quick demo of how this looks like

sys-demo

The watch command handles the "realtime" aspect, it can be used to perform operations like running a certain command periodically.
The -c flag enables the watch to render ANSI colors.
The default interval for the watch command is 2 seconds but can be configured using the -n option.

Save the above script and use it like this:

watch -ct -n0 sys.sh
Enter fullscreen mode Exit fullscreen mode

If you have any other ideas, drop them below ๐Ÿ‘‡

Seems interesting?, Subscribe ๐Ÿš€ to receive more such cool stuff or just connect with me on twitter.

Discussion

pic
Editor guide
Collapse
moopet profile image
Ben Sinclair

The default interval for watch is 2 seconds. 0.1 seconds is the minimum granularity it'll let you aim for.

Collapse
bhupesh profile image
Bhupesh Varshney ๐Ÿ‘พ Author

Ah yes ๐Ÿ˜ฌ.
Thanks for correcting ๐Ÿ‘๐Ÿฝ

Collapse
kkumar326 profile image
Kshitij Kumar

nice article

Collapse
bhupesh profile image
Bhupesh Varshney ๐Ÿ‘พ Author

Thanks โœŒ๐Ÿฝ