Recommended Services
Supported Scripts

Find is a very useful utility available in all the Linux server across all the variants, in this post let’s discuss some of the use cases of the command “find“.

You are in a directory with thousands of files and you want to specifically search for “.png” and “.php” files.

You can achieve this by running the following command on the bash and in the directpoy where you want to initiate a search.

find . -type f \( -name "*.png" -o -name "*.php" \)

Below would be the expected output

[root@localhost ]# find . -type f \( -name "*.png" -o -name "*.php" \)
./includes/mail.php
./includes/pipe.php
./includes/upgrade.php
./includes/controller.php
./includes/contact-form-template.php
./includes/js/jquery-ui/themes/smoothness/images/ui-bg_glass_75_dadada_1x400.png
./includes/js/jquery-ui/themes/smoothness/images/ui-icons_222222_256x240.png
./includes/js/jquery-ui/themes/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
./includes/js/jquery-ui/themes/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
./includes/js/jquery-ui/themes/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
./includes/js/jquery-ui/themes/smoothness/images/ui-icons_2e83ff_256x240.png
./includes/js/jquery-ui/themes/smoothness/images/ui-icons_888888_256x240.png

Now, let say you want to search for two specific files in a directory. You know the names of the files that you want to search, in that you can use the below command syntax to find those files that you are looking for.

File names that I want to search is “functions.php” and “config.php

[root@localhost public_html]# find -name "config.php" -o -name "functions.php"

Below would be the expected output

[root@localhost public_html]# find -name "config.php" -o -name "functions.php"
./plugins/akismet/views/config.php
./plugins/contact-form-7/includes/functions.php
./plugins/all-404-redirect-to-homepage/functions.php
./plugins/wordpress-seo/vendor/yoast/api-libs/google/config.php
./themes/frontier/functions.php
./functions.php