How to search or find a File / Folder on your Linux Server ?

To locate files or folders on your Linux server through command line or bash, you can use the ‘find‘ command.
The syntax for the find command is as follows :

find {dirctory_to_search} {search_by} {pattern_to_search} [action]

For Example, if you wish to search a file called ‘filename.php’ by name on the entire server.

fine / -name filename.php 

Some of the popular ‘search by’ options are :

-name pattern : This option finds the filenames of the given pattern.

For Example : Find a file named ‘myfile.txt’ in the ‘home’ folder of the server.

find /home -name myfile.txt

-user username : Finds files owned by the given user name.

For Example : Find Files owned by the user ‘WPOven’ in the ‘/var/usr’ folder of the server

find /var/usr -user WPOven

-perm permission : Finds files of the given permissions.

For Example : Find all files with permission as ‘665’ in the ‘/srv’ folder

find /srv -perm 665

-type X : Search files of type X. Here X can be :

f – File
d – Directory
l – Symbolic Link
For Example : Find a directory with name like ‘mydir’ in the ‘/var/www’ folder

find /var/www -type d -name mydir

-print File : Print the result full filename followed by a new line.

For Example : Find the files with name temp in the /srv folder and delete them

find /srv -type f -name temp -print | rm -f