Skip to content

Searching for certain file names via SSH or command line: Locate and Find Commands

Jul 16, 2014 | Services

There are times when a server administrator needs to search along a path, or for that matter, the entire server for certain file names or file patterns.

Here is a useful command to conduct such searches via SSH on a standard Linux system.

I use this on Centos 5/6 frequently: In this example we are looking for a file called test.png

These were found using `find and `locate`

root@host ~]# find / -iname test.gif 

/usr/local/cpanel/base/editarea/edit_area/plugins/test/images/test.gif
/home/cpeasyapache/src/php-5.3.28/ext/oci8/tests/test.gif
/home/cpeasyapache/src/php-5.3.28/ext/fileinfo/tests/resources/test.gif

Using the locate command in SSH can do the same thing, only notice that it will grab instances of file names where the string searched for also appears – such as the conv_test.gif match.

[root@host ~]# locate test.gif

/home/cpeasyapache/src/php-5.3.28/ext/fileinfo/tests/resources/test.gif
/home/cpeasyapache/src/php-5.3.28/ext/gd/tests/conv_test.gif
/home/cpeasyapache/src/php-5.3.28/ext/oci8/tests/test.gif

/usr/local/cpanel/base/3rdparty/Logaholic/images/icons/savedtest.gif
/usr/local/cpanel/base/3rdparty/Logaholic/images/icons/splittest.gif
/usr/local/cpanel/base/editarea/edit_area/plugins/test/images/test.gif

Use these commands to serach your entire server, which obviously can take a while depending on your size, speed and the total number of files it needs to look through.

You can “find” more information and syntax examples here: https://www.tecmint.com/35-practical-examples-of-linux-find-command/

You can “locate” more information and syntax examples here: https://www.thegeekstuff.com/2012/03/locate-command-examples/

Contact Us Today!

"*" indicates required fields

This field is for validation purposes and should be left unchanged.
I would like to be contacted by:*
Select all that apply.

Join Our Newsletter List!

* indicates required
Test