chmod all .htaccess files under all website dirs under public_html dir This is my code to chmod all .htaccess files under all website dirs under public_html dir.

The reason I use this code is to make sure WordPress plugins won't "freak out" and change my .htaccess file undesirably.

This is a shared server environment so I can't access htppd.conf instead, and must edit the different .htaccess files per each site, with the below code:

for dir in "$HOME"/public_html/*.{com,co.il}/; do
  if pushd "$dir"; then
    chmod 644 .htaccess
    popd
  fi
done 2&gt;/dev/null
Instead of manually scanning each files and directory and testing if they are a directory using pushd, I would directly try to target .htaccess files using find:

find "$HOME"/public_html/*.{com,co.il} -name ".htaccess"


Then, to apply the proper permissions, you can use the -exec option of find:

find "$HOME"/public_html/*.{com,co.il} -name ".htaccess" -exec chmod 644 {} \;