General Commands

From INIwiki
Jump to: navigation, search


[edit] CPU Utilization

Find Linux CPU utilization using mpstat and other tools Please note that you need to install special package called sysstat to take advantage of following commands. This package includes system performance tools for Linux (Red Hat Linux / RHEL includes these tools by default).

apt-get install sysstat

Display the utilization of each CPU individually using mpstat If you are using SMP (Multiple CPU) system, use mpstat command to display the utilization of each CPU individually. It report processors related statistics. For example, type command:


Find out who is monopolizing or eating the CPU, determine which process is monopolizing or eating the CPU. Following command will displays the top 10 CPU users on the system.

ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

ps -eo pcpu,pid,user,args | sort -r -k1 | less
Many Good Commands…

See here to Generate Artificial Load

[edit] Memory Utilization Commands

free -m -t
cat /proc/meminfo
grep 'MemTotal:' /proc/meminfo

[edit] Grep and xargs commands

Find and remove all directories that are older than 90 days:

find /dir/location -type d -mtime +90 |xargs rm -rf

Find and remove files:

find ./ -iname S*bind* | xargs rm -rf

Remove commented lines from files

grep -v ^# filename |uniq > comm.txt

[edit] Whats under the "hood"

Run this command to see CPU info

cat /proc/cpuinfo 

Run this command to see Memory info

cat /proc/meminfo

Run this command to see which distribution you are running

cat /etc/*release*

Run this for simple kernel information (kernel-release)

uname -r

...for more detailed system information

uname -a

List PCI devices


[edit] List Connections on a Port

This one will show you the maximum connections from a IP on port 80 and sort it uniquely. Pretty useful when the server is being a victim of DOS attack.

netstat -plant | grep :80 |awk {'print $5'} | cut -d: -f1 |sort | uniq -c | sort -nk 1

You can use this command to see connections on any port by changing the :80 section to the port you want IE: ssh

netstat -plant | grep :22 |awk {'print $5'} | cut -d: -f1 |sort | uniq -c | sort -nk 1

[edit] File Details

Shows Access, Modified, and Changed dates


[edit] Recall Command Line entry

ctrl r
Then start typing the command you want to call out of your bash history

[edit] Sources

CPU Util:
 -- Many Good Monitor Commands
Personal tools