loading...

Get complete system info using shell commands

bhupesh profile image 𝔹𝕙𝕦𝕡𝕖𝕤𝕙 𝕍𝕒𝕣𝕤𝕙𝕟𝕖𝕪 👾 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)

## Network usage stats
net_device=$(route | awk '/default/ {print $8}')
TRANSMITTED=$(ifconfig "$net_device" | awk '/TX packets/ {print $6$7}')
RECEIVED=$(ifconfig "$net_device" | awk '/RX packets/ {print $6$7}')

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 "%s\n\n" "${BOLD_GREEN_FG}Network Usage since${RESET} $pc_uptime"
printf "%s\n" "🔼 TRANSMITTED : $TRANSMITTED"
printf "%s\n" "🔽 RECEIVED    : $RECEIVED"

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.

Posted on by:

Discussion

pic
Editor guide
 

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