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
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 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
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 --
# 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