ethtool eth0
List addresses for interfaces:
ip addr show (OR) ip a
Set default gateway:
ip route add default via 1.2.3.254
List routing table:
ip route show
Add additional IP's on server
ifconfig eth0:0 192.168.1.174 netmask 255.255.255.0 up
Add (or del) ip and mask (255.255.255.0):
ip addr add 1.2.3.4/24 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
Output:
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'
Output:
%CPU CPU NI S TIME COMMAND
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 innovationframes.com
Output:
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/5.0.2.2635
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.
Output:
12 218.248.35.90
7 122.167.25.155
1 80.240.220.83
1 65.55.106.143
1 216.129.119.13
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@10.0.0.1:/root
SCP with nohup:
nohup scp -P 52783 -r library root@69.20.92.166:/var/www/vhosts/example.net/httpdocs/ &
Rsync:
rsync -vrplogDtHe 'ssh -p 25873' /var/www/vhosts/rsync_test root@10.0.0.1:/var/www/vhosts/ >/dev/null 2>&1
Options:
-vrplogDtHW
-v -> increase verbosity
-r -> recurse into directories
-p -> preserve permissions
-l -> copy symlinks as symlinks
-o -> preserve owner (super-user only)
-g ->
-D->
rsync -vrplogDtHe 'ssh' /var/abc/cde/xyz.com/test/ root@10.10.43.20:/var/xxx/xxx/abc.com/test/
Above command will synchronize the data from '/var/abc/cde/xyz.com/test/'(source) to '10.10.43.20:/var/xxx/xxx/abc.com/test/'(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"
here,
/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
Ref:
http://www.cloudlinux.com/blog/clnews/?PAGEN_1=8
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"