CityHost.UA
Help and support

Search for files and directories on the server

In this guide, we'll look at how to search for files and directories. This instruction is relevant both for virtual hosting servers and for virtual and dedicated server services, since all examples use SSH console commands.

The find command

This command is used to search for files by their name or attributes.

Find the index.php file starting from the directory where you are now (-iname — ignore case characters)

 find -iname "index.php"

Find the index.php file by specifying the path to a specific directory

 find /var/www/ch12345678/www/mysite.com -iname "index.php"

Find all files with the extension php (* — searches for any character)

 find -iname "*.php"

Find a file knowing only part of the name

 find -iname "ind*"

Find files larger than 500 megabytes (+500 - more than 500, -500 - less than 500, main combinations - k, M, G)

 find -size +500M

The grep command

This command is used to search for text inside files. It is convenient to search for files without knowing their name, but knowing the code or text they contain.

Find files in which the text sometext occurs (r — recursive search, i — ignore case, n — line numbers, o — hide redundant output)

 grep -rino "sometext"