Thursday, 5 January 2017

File Permissions in UNIX

rwx(owner user)-rwx(group)-rwx(other)

0 - no permission
1 -> x only
2 -> w only
3 -> wx only
4 -> r only
5 -> rx only
6 -> rw only
7 -> rwx - all


chmod -R 777 to change file permissions.




Wednesday, 4 January 2017

Beauty Of Grep

Usage:grep keyword filename

1) How to ignore some words while doing search using grep in UNIX:

Example:
grep Exception logfile.txt | grep -v Error

2) How to count occurrence of a word in a file using grep command:

grep -c Exception logfile.txt



3) Printing lines after  or before matching a word :

grep -C 6 Exception logfile.txt



4) How to search pattern using egrep and regular expression:

We can use '|' to search for either Error or Exception in single comand

egrep 'Error|Exception' filename.txt



5) -i can be used for case insensitive search

6) zgrep can be used to search patterns in gz files.

7) How to search a whole word in file using grep

grep -w word filename









Tuesday, 3 January 2017

How To Find Out List Of All Open Ports in Linux

Network Statistics(Netstat) can be used to identify all incoming and outgoing connections in a system.

List out all connections: netstat -a




If we want to display only tcp connections, then 't' option can be used to along with option a.
Similarly 'u' option to display UDP connection details.

When viewing the open/listening port and connections,it's often useful to know the process name/pid which has opened that port or connection.

Note: When using p option, netstat must be run with root privileges.

n -> No reverse dns lookup to speed up the output.
l --> Display only listening(established) connections.
t --> Interested only in tcp connections.
p --> Display who opened those connections.
e --> Display user id




Check if a service is running: use grep with pipe

 

Print netstat output continuously (option c)

netstat -cnt | grep ESTABLISHED













FIND Any File or Directory in LINUX

Find command can be used to locate files in LINUX.

Default Usage:

find directory  -name name