Linux CentOS – copy .htaccess file into every subdirectory

If you need to copy a file into every sub-directory within a directory, navigate there, and run this command:

find -type d -maxdepth 1 -print0 | xargs -0 -n1 cp .htaccess

The maxdepth 1 switch allows you to go only 1 subdirectory deep, you can change it to 2, or 3 or leave it out altogether to copy into every subdirectory, regardless of depth. You can copy any file, not just .htaccess this way.

find -type d -print0 | xargs -0 -n1 cp .htaccess

This can be especially useful for WordPress media files and upload directories organized by month/year, or osCommerce phpThumb or other cache directories that have write permissions set to 777.