2.11.3. Search files and directories using console

Using the console and the find utility, you can search for files and directories based on various criteria. In commands, instead of the dot . you can specify the path to the specific directory in which you want to perform the search.

To search for all files and directories by name (case-insensitive) in the current directory and all its subdirectories, use the command:

find . -iname NAME

In the command, replace NAME with the name of the file or directory you are searching for.

To search for all files with the extension .php (case-insensitive) in the current directory and all its subdirectories, use the command:

find . -iname '*.php'

To search for all files larger than 1000 KB in the current directory and all its subdirectories, use the command:

find . -size +1000k

To find all files smaller than 500 B in the current directory and all its subdirectories, use the command:

find . -size -500b

The size can be specified in different formats: 10 — bytes, 10k — KB, 10M — MB, 10G — GB.

To find all files and directories that have been modified in the last 24 hours in the current directory and all its subdirectories, use the command:

find . -mtime 1

To find all files and directories that have been modified in the last 15 minutes in the current directory and all its subdirectories, use the command:

find . -mmin 15

To find all files and directories modified between 5 and 10 days ago in the current directory and all its subdirectories, use the command:

find . -mtime 5 -mtime -10 -daystart

To search for all files with the extension env, php, xml, yml or ini containing the specified string fragment in the current directory and all its subdirectories, use the command:

find ./ -type f -regex ".*\.\(env\|php\|xml\|yml\|ini\)" -exec grep -i -H "STRING" {} \;

In the command, replace STRING with the text you are searching for.

To search all files in all directories recursively, use the command:

grep -rn "STRING" ~/
Content