Tag-Archive for » linux command «

Friday, October 17th, 2008 | Author: Angelo

Command grep is used for printing lines which matches to a pattern you have defined.
Exercise ::
For example there is one file name is test contains following lines.
is it test file ?
is it test file

Now pattern you defined is ? means you are trying to print all lines which contain ? (question mark) from file test.
Usually we try follow command.
cat test | grep ?

But output will show both lines because grep treat ? as single character both lines contains more than single character. Solution for grep lines containing ? (symbol) is define ?(special character) in []
cat test | grep [?]
is it test file ?

Same in case of all special character *, . , ‘ , ” , }, ) . This trick will help you when you need to search all lines containing defined pattern from log files. Also useful in shell scripting.

Wednesday, October 08th, 2008 | Author: Angelo

Hello,

Below is command to find out number of connections from each ip to server using netstat , sort, uniq, awk.

netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

Here is description of Grep used in this command :: Grep is used for sorting lines which are matching for defined pattern but if you want to sort such lines which are matching two or more different pattern then simply define all patterns in single quote and separate them using \| .

Thursday, October 02nd, 2008 | Author: Angelo

Hello,

Below is command to find out number of connections to each port using netstat, cut, awk ,uniq.

netstat -na | grep 'tcp\|udp' | awk '{print $4}' | cut -d: -f2 | sort | uniq -c | awk '{print $2}'

Here, is description for this command so many times you may face trouble because of dos attack in such case you need to find port number (service) on which dos attack is going on above command will help you to search number of connections to each port which is in use.