Posts tagged ‘grep’

Finding large files and directories on Linux

terminal.png

Use this simple command to find large directories. To find directories over 1GB

[root@localhost]# du -h / | grep ^[0-9\.]*G

G can be replaced with M if looking for MB instead.

To find directories over 10GB and sort the output with the largest directories on top

[root@localhost]# du -h / | grep ^[1-9][0-9][0-9\.]*G | sort -rn

Continue reading ‘Finding large files and directories on Linux’ »

Kill a process by it’s port

terminal-glossy.jpg

Have you ever faced problem of busy ports?

Here is the solution to kill a process which is occupyingh any specific port.

/usr/sbin/lsof | grep | kill -9 `awk ‘{print $2}’`

If you want to kill a proces who is using a port say 9999, issue command:
/usr/sbin/lsof | grep 9999 | kill -9 `awk ‘{print $2}’`

Basics of Using Grep

terminal-glossy.jpg

Grep is a command line utility that was originally written for use with the Unix operating system. Given a list of files or standard input to read, grep searches for lines of text that match one or many regular expressions, and outputs only the matching lines.

Grep allows you to search files for symbols or strings (groups of characters like words) and will return the files that the search sting is found in. For example you want to search a website’s access log file for a recent traffic that came from a search engine. Most search engine referral urls have a question mark in them. The Grep command would look something like this:

grep [search string] [file name]

Continue reading ‘Basics of Using Grep’ »