Your browser (Internet Explorer 6) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browser.
X
Aside

Searching For Files with Find

I’ll start with some quick examples for the “copy and paste” crowd, which I’m usually a part of. 

Search the entire file system for files named php.ini.

sudo find / -name 'php.ini'

Search everything under the /etc directory for files named nginx.conf.

sudo find /etc -name 'nginx.conf'

Search the entire file system for file names ending in .cnf.

sudo find / -name '*.cnf'

If your like me when I was starting out you’ve probably fumbled with the find command before. Like many powerful command line tools you need to learn a few basics before you can start harnessing any of its powers.

The two things you need to know about find are how to specify the search path and file name to look for. The search path is the first parameter and it defaults to searching the directory your currently in. It’s a bit counter intuitive since these days most tools search everything by default and then provide filters. To specify the entire filesystem use “find /”.

The second most used flag is “-name”. This allows you to specify the file name you’re looking for. Be sure to include the actual file name in quotes or you’ll get unexpected results. You can use the asterisk * symbol for wildcard matches.

I’ll mention one more option that you’ll find helpful when your searching for files and that’s the “-user” flag. Specifying a user filters search results to only show files owned by that user. The “-user” flag doesn’t require quotes.

Find all php files owned by the web server.

sudo find / -user www-data -name '*.php'

That should be enough to get you started! For more tips follow this post and learn how to search for files above a certain size.