How to delete all .htaccess files with one command

The ability to delete all .htaccess files with one command is an action that will make it easier for you to clean your site.

Lately, there is malware that places a “harmful” .htaccess file in every folder of the WordPress site, and this can cause great damage, but it also requires a lot of time to delete one file at a time.

Fortunately, there is a very easy way to delete all .htaccess files with a single command.

Note that you need SSH access to the site.

Before you start deleting .htaccess files

Check the main file located in the root of the site directory and make a copy of that file. Save a copy of the file somewhere on the side (perhaps on your computer).

Be sure to check that file for potentially harmful directives.

If the main .htaccess file is also compromised, you will need to manually clean all harmful directives and later restore it to the hosting.

List all .htaccess files with one command in text file

You may need this list later. For example, if you want to see exactly where all the .htaccess files were, or if you’re doing a site cleanup for a client and want to show exactly what was deleted (that’s what I do).

First, connect to the site via SSH connection and enter the root directory of the site.

To list all .htaccess files type:

find . -type f -name ".htaccess"

To list all .htaccess files and write that list in the text file type:

find . -type f -name ".htaccess" > PATH/htaccess_list.txt

Don’t forget to enter the exact location where you want to save that .txt file. In the command above there is an example that you have to modify.

Delete all .htaccess files with one command

If you have done everything you wanted so far, you can run the command to delete all .htaccess files.

Connect to the site via SSH connection.

To delete all .htaccess files in the specific directory run:

find /PATH/ -name ".htaccess" -delete

Keep in mind that you have to replace /PATH/ from the command above with the exact path of the directory where the site is located.

This command will delete all .htaccess files from the specified directory within a few seconds. This process is irreversible.

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