Searching using the command line 

Something that you may have to do occasionally is find a file on your computer but you don’t know or can’t remember where it is. Lucky there is a command that solves this, actually there are more than one command some have more specific purposes than others but the following command is enough to get you started.

find <search directory> -name <search string>

while searching for a file is useful what if you want to find something in a file that is where the grep command is used.

grep <search string> <file>

to make it case insensitive

grep -i <search string> <file>

you can also use grep with the output of other commands using a pipe “|” this redirects the output of one command into another. To use a pipe just put it between the two commands. In the example below I will use the ps command which lists all the processes running on the computer and pipe it into grep.

ps -A | grep <search string>

In this case you don’t need to list the file as the pipe supplies the input

This is only a fraction of what can be done with these commands to find out what other features they have take a look at the man pages which can be viewed using the following command

man <command>


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s