June 20, 2020

Search In Bash

To Implement Search in bash the following are commands that might come handy


The find command is used to find files and folders in a directory

1find newfolder/

The above command finds all the content of the folder

To find a specific file in a directory use the following

1find newfolder/ -name aaa.txt

To find a specific type of content in a directory

1find newfolder/ -type file


The grep command is used to find the content of a file and when it finds a match it prints out the line that matches search.

Example To find “so” in a text file called b.txt

1grep so b.txt

Note the grep command is case sensitive

1grep so b.txt

is different from

1grep So b.txt

We could also use

1grep -v So b.txt

the above is used to find lines which does not contain “So”

Written by Adeyemi Adekorede
You can follow him on Twitter