Ubuntu: Rename all .htaccess files on server


On my localhost I have enabled htaccess evaluation in apache2.conf and now I keep getting 500 (Internal Server Error).

I think I have some faulty .htaccess files that not being evaluated caused no issues before, but now are causing the error. I used find /var/www/ -name ".htaccess" -print to find the files, but they are too many.

For now, I would like to rename ALL .htaccess files to old.htaccess wherever they are. Using: rename .htaccess old.htaccess results in this error in terminal:
syntax error at (eval 1) line 1, near ".".

Wrapping the filenames like rename ".htaccess" "old.htaccess" produces the same error.

What is the correct command to use.


rename doesn't work that way; you need to specify a PCRE (Perl Compatible Regular Expression) pattern and replacement to work with it.

For this purpose, mv is enough; a fast way to rename all the .htaccess files in /var/www would be to use find itself:

find /var/www -type f -name '.htaccess' -execdir mv {} old.htaccess \;  

Sample output on a test hierarchy:

user@debian ~/tmp % tree -a  .  â"œâ"€â"€ 1  â"‚   â""â"€â"€ .htaccess  â"œâ"€â"€ 2  â"‚   â""â"€â"€ .htaccess  â""â"€â"€ 3      â""â"€â"€ .htaccess    3 directories, 3 files  user@debian ~/tmp % find . -type f -name '.htaccess' -execdir mv {} old.htaccess \;         user@debian ~/tmp % tree -a  .  â"œâ"€â"€ 1  â"‚   â""â"€â"€ old.htaccess  â"œâ"€â"€ 2  â"‚   â""â"€â"€ old.htaccess  â""â"€â"€ 3      â""â"€â"€ old.htaccess    3 directories, 3 files  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »