UNIX-1.8 ps, netstat, kill, pidof, fuser, awk commands


Make sure to subscribe to my channel for more videos on UNIX, Perl and SQL.
facebook: facebook.com/fuzicast
twitter: @fuzicast
youtube: youtube.com/yuejdesigner85

ps -fu username – displays all processes started by user
ps -ef – display all processes running
ps -ef | grep ‘pname’ – look for specific process
netstat -t – see all tcp connections
netstat -an – see all network connections
netstat -c – netstat will execute every second
netstat -p – display processes that use these connections
kill pid – kills process by pid
kill -9 pid – force kill process by pid
& – execute process in background
free – show memory usage, alternatively use top
pidof command – shows process id for running process/command
fuser -vu dir – displays all processes that are using dir, along with owner id of processes
echo “hello world” | awk ‘{ print length($1) }’ – prints length of field
echo “hello world” | awk ‘{ print substr($1, 3) }’ – prints llo, substring function
echo “hello world” | awk ‘{sub(regex, replacement); print}’ – replace pattern on line and print
echo “HELLO world” | awk ‘{ print tolower($1) }’ – lower case field 1
echo “hello world” | awk ‘{ print toupper($1) }’ – upper case field 1

Advertisements

UNIX-1.5 Awk, Cut, Last, Wc Commands Video Tutorial


Make sure to subscribe to my channel for more videos on UNIX, Perl and SQL.
facebook: facebook.com/fuzicast
twitter: @fuzicast
youtube: youtube.com/yuejdesigner85

awk -F’|’ ‘BEGIN{ initialization } { code block } END{ finalization }’ – general syntax
default delimiter is space ‘ ‘
VAR=”value” – define a variable
print VAR – print a variable
NF is number of fields
$NF is value of last field
print “‘$EXTERNAL_VAR'” – double single $EXTERNAL_VAR single double
VAR~/pattern/ – pattern patching
VAR!~/pattern/ – does not match
FS returns value of field separator, same as -F
OFS returns output field separator
print $1,$2 is separated
NR returns line number
FILENAME returns current filename
awk -v var1=value1 – pre-assign values to variables in awk
awk -F, ‘conditions { code block }’ filename – condition must be right before code block

cut – get columns from file
cut -d, -f1-2 filename – print 1st to 2nd columns
cut -c1-5 filename – print first 5 characters
cut -d, -f2- filename – print from 2nd column to last column
cut -d, -f1,4,5 filename – print 1st, 4th and 5th column
cut -d, -f-3 filename – print from 1st to 3rd column
cut -d, -f1,3-5 filename – print 1st, 3rd to 5th column

wc – word count
wc -l – line count
wc -c – print number of bytes
wc – print number of newline, word and bytes
wc -m – character count
wc -w – word count

last – check login history
last -10 – show last 10 logins
last -F – show full login information