$: cat tags > command | console | extension | find | сервер

Find all files by extension on Linux, CentOS, Alma, Ubuntu

Any administrator may often need a command that can find all files by extension on Linux.

This is especially useful if you’re cleaning up a site and want to find all the files that have a specific extension.

For example, I often clean WordPress for my clients and one of the cleaning steps is to make sure the wp-content folder does not contain PHP files.

I can do that easily in a few seconds with this command that searches all files by extension.

The command to search for files by extension is simple and looks like this:

find /PATH/ -type f -iname *.php

Don’t forget to replace /PATH/ with the appropriate path where the directory you want to search is located.

Don’t forget to replace php with the other extension you are looking for.

For example, if you want to search for it in the WordPress site of a user whose site is located in the path:

/home/max/public_html/wp-content/

then the command should look like this:

find /home/max/public_html/wp-content/ -type f -iname *.php

This command above will search the entire folder in this location:

/home/max/public_html/wp-content/

and it will list all php files.

List all files with the requested extension and create a list in the file

If the list is too long and difficult to read, you can rewrite the command so that the list is written to a file.

You just need to add the following to the command:

> /PATH/file-name.txt

it will look like this in the example above:

find /home/max/public_html/wp-content/ -type f -iname *.php > /home/max/public_html/wp-content/file-name.txt

This command will search all php files in this directory:

/home/max/public_html/wp-content/

and will list those files in a text file here:

/home/max/public_html/wp-content/file-name.txt

I hope this command will help you in working on Linux when browsing files by extension. I often use it and in this way I search for suspicious php files as well as many other files.

Author, Ivan Blagojević

Engineering Lead at Adriahost. I spend most of my time on Linux operating systems with cPanel/WHM panels.

I help people solve problems and choose the right hosting for their site.

I write here in my spare time.

Time4VPS - VPS hosting in Europe