Board index Linux Linux - Commands and Tools

Moderator: chandranjoy

Advanced Linux Commands

Postby chandranjoy » Mon Mar 01, 2010 2:02 am

Show status of ethernet interface eth0:
ethtool eth0

List addresses for interfaces:
ip addr show (OR) ip a

Set default gateway:
ip route add default via

List routing table:
ip route show

Add additional IP's on server
ifconfig eth0:0 netmask up

Add (or del) ip and mask (
ip addr add brd + dev eth0

Text Manipulation:

Replace string1 with string2:
sed -i 's/string1/string2/g'

Modify anystring1 to anystring2:
sed -i 's/\(.*\)1/\12/g'

Remove comments and blank lines:
sed -i '/ *#/d; /^ *$/d'

Case conversion:
echo 'Test' | tr '[:lower:]' '[:upper:]'

List processes by memory(KB) usage:
ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS


11572 /usr/local/apache/bin/httpd -k restart -DSSL
11896 /usr/local/apache/bin/httpd -k restart -DSSL
15228 tailwatchd
19404 MailScanner: starting child
22032 MailWatch SQL
27652 /usr/sbin/named -u named

To find the history of load on a server

sar -q
Refer: viewtopic.php?f=5&t=171

Processes by CPU usage:
ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d'


0.1 – 0 S 00:00:00 /usr/local/apache/bin/httpd -k restart -DSSL
0.1 – 0 S 00:00:00 /usr/local/apache/bin/httpd -k restart -DSSL
0.1 – 0 S 00:00:00 /usr/local/apache/bin/httpd -k restart -DSSL
0.1 – 0 S 09:40:37 [kjournald]

How to find the webserver(IIS or Apahce) through command:
curl -I

HTTP/1.1 200 OK
Date: Sat, 18 Dec 2010 14:53:52 GMT
Server: Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/
Last-Modified: Tue, 16 Nov 2010 12:13:48 GMT
ETag: "15bc42d-a85-7d2b5700"
Accept-Ranges: bytes
Content-Length: 2693
Content-Type: text/html

List processes in a hierarchy:
ps -e -o pid,args --forest

Show system reboot history:
last reboot

List paths that process id has open:
lsof -p $$

List processes that have specified path open:

lsof /home

Find the php files and change the permissions using find command:
find . -type f -name \*.php -exec chmod 644 {} \;

Find the full permission folders and change the permissions using find command
find . -type d -perm 777 -exec chmod 755 {} \;

List the number of current connections(top 10) of port 80 (with IP):
For CentOS/RedHat/Fedora Servers:
netstat -tn|grep :80|awk '{print $5}'|cut -d: -f4|sort|uniq -c|sort -rn|head
netstat -tn|grep :80|awk '{print $5}'|cut -d: -f1|sort|uniq -c|sort -rn|head

For Ubuntu/Debian Servers:
netstat -tn|grep :80|awk '{print $5}'|cut -d: -f1|sort|uniq -c|sort -rn|head

This command will list the IP’s which are currently using the mentioned port-80(http) and the number of connections of that too.


To display apache connection states and the no. of requests:
netstat -an|grep ":80"|awk '/tcp/ {print $6}'|sort| uniq -c

To remove apache Semaphores:
ipcs -s | grep nobody | perl -e 'while (<STDIN>) { @a=split(/\s+/); print `ipcrm sem $a[1]`}'

This command will remove the apache semaphores.
Note: This will stop the apache and you need to start the apache again.

SCP with different port:

scp -P 25873 libfaad0-2.6.1-13.el5.x86_64.rpm root@

SCP with nohup:
nohup scp -P 52783 -r library root@ &

rsync -vrplogDtHe 'ssh -p 25873' /var/www/vhosts/rsync_test root@ >/dev/null 2>&1
-v -> increase verbosity
-r -> recurse into directories
-p -> preserve permissions
-l -> copy symlinks as symlinks
-o -> preserve owner (super-user only)
-g ->

rsync -vrplogDtHe 'ssh' /var/abc/cde/ root@
Above command will synchronize the data from '/var/abc/cde/'(source) to ''(destination)

To Find out which account originates SPAM:
ps -C exim -fH eww | grep home

To Find out When was the Operating System installed?
tune2fs -l <filesystem block device> | grep -i "Filesystem created"
For an example:
tune2fs -l /dev/sda1 | grep -i "Filesystem created"
/dev/sda1 -> /boot

Here is easy way to find out which programs take up most RAM. While it doesn't account for lots of things like shared memory -- it is still very useful. It adds up RSS field from ps output by application, and sorts them up in descending order.
The first column is RSS usage in MB.

Code: Select all
ps -eo comm,rss|awk '{arr[$1]+=$2} END {for (i in arr) {print arr[i]/1024, i}}'|grep -v '^0 '|sort -n -r


Did you know that the following command displays the Linux server boot time
Code: Select all
date -d "$(cut -f1 -d' ' /proc/uptime) seconds ago"
Site Admin
Posts: 283
Joined: Fri Oct 23, 2009 11:19 pm

Return to Linux - Commands and Tools

Who is online

Users browsing this forum: No registered users and 1 guest