Thursday 5 December 2013

advanced linux commands for quick system analysis

There are many linux commands which helps in many ways . If you are not linux administrator then these commands can help you in many ways .
Following commands are very important .

advanced Linux commands

ifconfig
netsat
nslookup
who
w
who am i
whoami
uptime
wall
top
rsync
lsof
find 
whereis 
alias
unalias
df
su
diff
traceroute
iostat
mpstat
iftop

ifconfig :- 

this command is used to setup network details . Also we can see ip address of the system . there are many uses of this command . complete usage of this command can be seen use command  "man ifconfig " .
some uses of that commands are :-
ifconfig -a   --> will show all details of networks 
ifconfig eth0 --> will show details of fist ethernet network
 ifconfig eth0 down --> will take first ethernet down  or shutdown ethernet first
 ifconfig eth0  up -->  just opposite to the down command . it will start firsth ethernet
ifconfig eth0 172.18.100.4  netmask 255.255.255.255 -->  will set system ip to 172.18.100.4 and netmast to 255.255.255.255

netstat :-

 netstat is very important command to use on servers . it shows details about all port activities . which port are working and how many connections on the ports at any time . complete usage of this command can be seen using command "man netstat" .
Some uses of this commands are :-
netstat -a --> will show all port activities
netstat -at --> will show all TCP port activities
netstat -au --> will show all UDP port activities
netstat -l --> ports which are listening
netstat -tl --> TCP ports which are listening
netstat -s --> statistics for all ports
netstat -st --> statistics for alls TCP ports only
netstat -n --> will show hosts in numeric form i.e. in ip address forms
netstat -c --> continuously

use many commands combinations to get your desired results . like :-
netstat -atn | grep ":8080 "  --> it will show connections on only 8080 port
also
 netstat -tan | grep ':80 ' | awk '{print $6}' | sort | uniq -c
2 CLOSE_WAIT
140 CLOSING
13371 ESTABLISHED
1884 FIN_WAIT1
116 FIN_WAIT2
110 LAST_ACK
1 LISTEN
367 SYN_RECV
2168 TIME_WAIT

nslookup :-

this command is used to see dns entries of any domain or ip . like
nslookup pkonline.in --> it wil show details about pkonline.in , its ip and max available info
nslookup 1.1.1.1 --> will show details about this ip address
nslookup pkonline.in 2.2.2.2 --> will show details of pkonline.in from dns 2.2.2.2

 traceroute :-


this command is used to trace route between your system to destination . use :-
traceroute google.com --> will show all nodes of connectivity between your system and google.com servers .


iostat :-


this command is used to get all input and output statistics over all hard disks. to install this command in system use  "yum install sysstat " .uses :-
iostat --> will show average of input and output operation on every disk partition .
iostat 2 --> will show continuously current io statistics .


mpstat:-


mpstat shows output stats of every processor available .
mpstat , mpstat -P all --> will how all processors statistics .
mpstat -P 0 --> will show just first processor output statistics .


uptime :-

it will show uptime of your server . that means from how much time your server is running . This will reset after restart of server . to use it just write uptime in shell and hit enter

wall :-

this command is used to send a message to all shells of that system . Suppose many people are logged in on that server . If any one want to convey any message to all people then use wall .like :-
wall "dont delete anyfile from directory /home/parveen" --> the message will appear to every one logged in the server

w,who,whoami ,who am i :-

these three commands will provide you details about how many user are logged in the system and from how much time .
w --> will show details of all logged in users .
who -- > similar to w but show less details .
whoami --> will show you your username .
who am i --> will show you more details about your login .

top :-

top is most basic and mostly used command . it can provide complete overview of your system . This will show CPU usage , RAM usage , load on system ,which process is using maximum system .etc .

htop :-

slightly modified version of top command . It show use individually of every CPU .

rsync :- 

this command is used to make two directoris in sync with each other . This can be used over two different systems or on the same system itself .

rsynch -uar /home/parveen/   /home/backup/ --> this will send all updated file from /home/parveen/ directory to /home/backup directory .
rsync --rsh='ssh -p22' -aur root@192.168.0.1:/home/parveen/images/    /home/parveen/images/ --> this command will get all files from different machine to current machine .

lsof :- 

it will provide list of open files . there are many uses of this command . like :-
lsof --> list all opened files on the system
lsof /home/parveen/parveen.log --> will show open statistics for specific file  /home/parveen/parveen.log
lsof +D  /home/parveen/  --> will show files open under directory /home/parveen/
lsof -u root --> will show files opened by user root .
lsof -p 10 --> will specify opened file by specific process .i.e process id 10 .

find :- 

this command is used to search any file in the system .this can be used like that :-
find /home/ -name abc.txt --> this command will try to search file abc.txt under directory /home/ .
find / -name abc.txt --> this command will find abc.txt in the whole system .
find . -name abc.txt --> this command will find abc.txt in the current directory .

whereis :-

this command will search the location of commands . like:-
whereis cp --> will show the location of cp command . This may also search is binary files .

alias :-

this command is used to create aliasing for any command. this command is helping to create shortcuts of commands .like :-
alias pp="ls -lhtr" --> after this if you run pp command this it will show results equivalent to ls -lhtr

unalias:-

this command will remove the alias created .like:-
unalias pp --> now pp will no longer be any alias .

df :-

this command is used to show storage usage of all hard disk partitions . like :-
df -k --> this will show all partitions witgh there usage and free memory available in bits.
df -kh --> this will show size in MB KB and GB format .

du :-

this command is used to show disk usage by directories and files . this can be used in maby ways .
du --> will show directories which are using some space that means files which are non empty .
du -a --> this comamnd will show all files . also will show empty files
du -ah --> will show memory in human readle form like KB MB GB .
du -s --> will show summarised memory .
du -sh * --> will show memory taken by all files and directory at your current location with human readable form .

diff:-

this command is used to find difference between two files . for comparison of two files this is well structured command .
diff file1 file2 --> will print differences between this two files  .

No comments:

Post a Comment