Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Tuesday, February 5, 2013

Command to find directory size in linux

du -sh <directory name>: 


Displays directory size in human readable format.

The sample output will be as following:

84M   <directory name>

du -sh ./* : 

Shows all the sub directories size in a human readable format.



Friday, December 28, 2012

Linux command to list out all processes running on a port: lsof

lsof means list open files, which lists all disk files, pipes, network sockets and devices opened by all processes.

lsof -i:80 list out all the processes running on port 80.

 # lsof -i:80 
 
COMMAND   PID     USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
apache2  2793 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3298 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3299 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3299 www-data   13u  IPv4 2991950      0t0  TCP li252-661.linod
apache2  3304 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3349 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3354 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3355 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3356 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3357 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3360 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2 25697     root    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)

Friday, December 21, 2012

Linux Commands Help: grep

Find text in a file:

 For example to find out "404" requests( page not found ) in apache log file:

grep "404" /var/log/apache2/access.log
 The above command displays all the entries contains the word "404".
   

grep -n "404" /var/log/apache2/access.log
The above command displays all the entries contains the word "404" with line numbers.
   

grep -c "404" /var/log/apache2/access.log
The above command displays the no. of entries contains the word "404"

grep -c "404\|192.168.20.32" /var/log/apache2/access.log
The above command displays the no. of entries contains both the words "404" and "192.168.20.32"