ssh find or search for file

In some cases you would need to find the location of a given file or to search for a certain text in all files under a directory. SSH provides two different commands, which can be used to accomplish this. In order to search for a file location you can use the find command. Find is a very powerful tool and accepts various arguments allowing you to specify the exact search term (i.e search by name, by type or even by modified time). You can also search for a given text in the files content as well. The command you should be using in this case is grep. Grep is a very powerful tool and accepts various command line arguments. For a full list it is recommended to check the manual pages by typing man grep. In some rare cases, you would not like to use find or grep. For example, to find a certain file in the whole server, it would be best to use an alternative command -- whereis or which.

# by filename
find . -name myFile.txt

# match a part of filename, use a wildcard pattern
find . -name “myFile*”

# list only directories and leave all files out of result
find . -type d

# filter only files modified for the last 2 days
find . -mtime -2


# using grep to find a certain text
# looks for string “database” in configuration.php
grep  “database” configuration.php

# if you don’t know which file contains the text
grep -r -H “database” *

# only list the file names containing search string 
# omit the line containing it
grep -l “database” *

# filter the results from other commands
ls -la | grep configuration.php


# find a certain file in the whole server
find a certain file in the whole server

# or
which perl