Searching for files/text using SSH

If you want to the find the files or folders under a specific location or directory,ssh provides two different commands.

find and grep command.

to search for a file location you can use the the find command.

For example if you want a search a file called abc.txt,you can use the below command

find . -name abc.txt

If you would like to list only directories and leave all files out of the result

find . -type d

if you want to filter only files modified for the last 2 days, you would need to use

find . -mtime -2

You can also search for a given text in the files content as well.This can be done by grep command.

An example of using grep to find a certain text

grep yyy "xxx.txt"

The above command instructs grep to look for the string “yyy” in xxx.txt file and display the containing line

Grep can also be used to filter the results from other commands

ls -la | grep xxx.txt

In some rare cases, you would not like to use find or grep.For example if you want to search a file on whole server you can use

whereis

or

which

commands.

Leave Your Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.