13,984 views 3,445 downloads 19 Aug 2016 History
3.7 avg · 0 ratings

netstat

netstat -atnup
My all time classic, see below for details.
netstat -an | grep ESTABL­ISHED | awk '­{print $5}' | awk -F: '­{print $1}' | sort | uniq -c | awk '{ printf­("%s­\t%­s\t­"­,$2,$1) ; for (i = 0; i < $1; i++) {print­f("*­")}; print "­" }'
Graph the number of connec­tions for each host
a: Show both listening and non-li­ste­ning,
t: Show TCP,
n: Show numerical addresses instead of trying to determine symbolic host, port or user names,
u: Show UDP,
p: Show the PID and name of the program to which each socket belongs.

tailf

tailf <fi­le>
Output the last 10 lines of a file
tailf -n 5 <fi­le>
Output the last 5 lines of a file
You have to use tail if you want to follow more than one file:

tail -f /var/l­og/­tom­cat­/fo­oba­r.log -f /var/l­og/­cat­ali­na.out

df

df -h
Show filesystem usage in human-­fri­endly format
df -i
Show inode usage
df -l
List only local filesy­stems (don't list NFS or SAMBA mounts)
More info about inodes: Check this doc !

iostat

iostat -x 5
Display full statistics for every filesy­stem, refresh every 5 seconds
The first report line provides statistics concerning the time since the system was started.

top

top
Display Linux tasks
top -p $(pgrep -d , foobar)
Monitor processes with the same name fragment '­foo­bar­'
Some intera­ctive commands
h: display help
c: toggle between process name only / full command line
u: show the processes for a specific user only
n: display a maximum of n processes
k: kill a process
H: show threads (also called Light Weight Processes)
z: toggle between monochrome and color display

ps

ps -ef
See every process on the system
ps -ejH
Print a process tree
ps -eLf
Get info about threads
ps -C java -o pid=
Print only the process IDs of apache tomcat
ps -o nlwp <PI­D>
Show the threads (Light Weight Processes) associated to a PID.

Shell keyboard shortcuts

Ctrl + a
Jump to the beginning of the line ()
Ctrl + e
Jump to the end of the line ()
Ctrl + l
Clears the screen
Ctrl + r
Lookup a command in history
Alt + .
Recalls last argument.

Badges

Nice Cheat Sheet Good Cheat Sheet Downloaded from Unusual Locations × 1

Comments (1)

notm1ke 23:26 11 Dec 2021

I received a syntax error when run this: netstat -an | grep ESTABL­ISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | awk '{ printf­("%s­\t%­s\t­"­,$2,$1) ; for (i = 0; i < $1; i++) {print­f("*­")}; print "­" }'

Reply

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.