Sponsored Content
Top Forums Shell Programming and Scripting Find all .htaccess files and make a backup copy in respective directories Post 302525963 by boxx on Monday 30th of May 2011 12:03:52 AM
Old 05-30-2011
I appreciate the responses, but I don't think that's quite what I'm looking for. Adding a date to the file... really doesn't get me anywhere, nor does a manual file by file copy to replace. Let me try to clarify...

I have approx 3,000 .htaccess files I am planning on targeting with a script to update them all at once removing a specified RE.

/dir1/.htaccess
/dir1/sub1/.htaccess
/dir1/sub2/.htaccess
/dir1/sub2/nest1/.htaccess
/dir2/.htaccess
/dir2/sub1/.htaccess
/dir2/sub2/.htaccess
/dir2/sub2/nest1/.htaccess
etc...

I've used:

Code:
find <start_directory> -iname ".htaccess" -exec cp -v {} {}_bak \;

To create a backup of each .htaccess to sit along side the original in every directory, so it now sits like this:

/dir1/.htaccess
/dir1/.htaccess_bak
/dir1/sub1/.htaccess
/dir1/sub1/.htaccess_bak
/dir1/sub2/.htaccess
/dir1/sub2/.htaccess_bak
/dir1/sub2/nest1/.htaccess
/dir1/sub2/nest1/.htaccess_bak
/dir2/.htaccess
/dir2/.htaccess_bak
/dir2/sub1/.htaccess
/dir2/sub1/.htaccess_bak
/dir2/sub2/.htaccess
/dir2/sub2/.htaccess_bak
/dir2/sub2/nest1/.htaccess
/dir2/sub2/nest1/.htaccess_bak
etc...

Now I'm going to run a script through all the original .htaccess files using find and sed -i to remove a selection of unwanted rewrite rules, while leaving the remaining rules in place. I'm pretty sure it is going to go as planned, but I want to be on the safe side and have backups in place, and a method to restore the original .htaccess files with the backups that reside along side them, if something goes wrong.

I need a method to find all .htaccess_bak files and rename them as .htaccess to overwrite the .htaccess files that are sitting along side them.

So in other words:

/dir1/.htaccess_bak is renamed to /dir1/.htaccess ... overwriting and replacing the .htaccess that is in place.
/dir1/sub1/.htaccess_bak is renamed to /dir1/sub1/.htaccess ... overwriting and replacing the .htaccess that is in place.
/dir1/sub2/.htaccess_bak is renamed to /dir1/sub2/.htaccess ... overwriting and replacing the .htaccess that is in place.

leaving a file structure like the original.

/dir1/.htacces
/dir1/sub1/.htaccess
/dir1/sub2/.htaccess
etc

But I need to do this for 3000 files at one time, not a cp or mv or rename... one by one by one manually..

I think this can be accomplished much along the lines of what I'm already using to create the backups. something like...

Code:
find <start_dir> -iname ".htaccess_bak" -exec rename {} {.htaccess} \;

I'm pretty sure the syntax there isn't correct, but I think it gives you an idea of what I'm trying to accomplish.

Any other thoughts or tips?

Thanks much!
BoxX
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

copy multiple files in different directories

I have a report file that is generated every day by a scheduled process. Each day the file is written to a directory named .../blah_blah/Y07/MM-DD-YY/reportmmddyy.tab I want to copy all of this reports to a separate directory without having to do it one by one. However, if I try cp... (3 Replies)
Discussion started by: ken2834
3 Replies

2. Shell Programming and Scripting

Make python script ignore .htaccess

I just wrote a tiny script with the help of ghostdog74 to search all my files for special content phrases. After a few modifications I now made it work, but one problem is left. The files are located in public_html folder, so there might also be .htaccess files. So I ignored scanning of that... (4 Replies)
Discussion started by: medic
4 Replies

3. UNIX for Dummies Questions & Answers

how can i copy those files into other directories have the same name

how can i copy those files into other directories have the same name but different in the end i have files in directory called test: 10_10_asdadfsdfad.txt 10_10_11_asdawqefwkjasd.txt 10_10_11_12_asdafjjhoqwd.txt i want to put them in exist directory thart i have on my system i have... (1 Reply)
Discussion started by: t17
1 Replies

4. Shell Programming and Scripting

Replace several numbers with respective tag and make a single file

Dear All, I have a final output files as 736645|0| 13879|1| 495563|10| 127933|14| 4975|16| 49038|6| 53560|7| 135115|8| 178857|9| Now I want to replace second column with respective tag as per the value (4 Replies)
Discussion started by: jojo123
4 Replies

5. Shell Programming and Scripting

Copy respective path next to last column with awk

Hi to all, I have the short print out sample of the DOS command "dir S/" as showed below. Directory of C:\Program Files\Winamp\Skins\Bento\window 02/12/2010 11:35 p.m. <DIR> . 02/12/2010 11:35 p.m. <DIR> .. 11/12/2009 10:31 a.m. 13,556... (3 Replies)
Discussion started by: cgkmal
3 Replies

6. Shell Programming and Scripting

Copy directories in make file

LD:=C:/WindRiver/diab/5.9.3.0/WIN32/bin/dld.exe CFILES:=$(wildcard *.c) OBJFILES:=$(subst .c,.o, $(CFILES)) OBJ_PATH:=$(PRJ_PATH)/out/ ADDOBJFILES := $(addprefix $(OBJ_PATH),$(OBJFILES)) FILES:=C:/EB/tresos/workspace/Test_Spi/output/src copyfiles: cp ... (3 Replies)
Discussion started by: ushacy
3 Replies

7. AIX

How to backup a directory (sub-directories/files) files from one server on to other ?

Hello, Server A: /directory1/ Server B: /Backups/ i wanted to backup contents of /directory1 from "server A" on to "Server B" every 1 hour. If there is any change in (only new/differences) contents on serverA (directory1/) supposed to be backeup on next run. I did used rsync command to... (5 Replies)
Discussion started by: System Admin 77
5 Replies

8. Shell Programming and Scripting

Copy files in respective directories

Hi Guys, I need to copy the files to respective directories based on name of the file. My script is something like below con=$1 for file in `cat $con` do file_tmp=$(ls -t1 $path| grep -i $file | head -n 1) echo $file_tmp if then cp $path$file_tmp $DIR/ap if then... (16 Replies)
Discussion started by: Master_Mind
16 Replies

9. Shell Programming and Scripting

Find and Copy Directories ONLY

I am trying to copy only the date specific folders/directories using the following command. However, the following copy command is also copying files from the root folder (OriginalFolder). find /OriginalFolder/ -type -d \{ -mtime 1 -o -mtime 2 \ } -exec cp -R {} /CopyTo/'hostname'__CopyTo/ \;... (2 Replies)
Discussion started by: apacheLinux
2 Replies
kbackup(1)						      General Commands Manual							kbackup(1)

NAME
kbackup - An easy to use backup program VERSION
0.7 DESCRIPTION
Kbackup is a program that lets you back up any directories or files. It uses an easy to use directory tree to select the things to back up and lets you save your settings in "profile" files. These are simple textfiles containing definitions for directories and files to be included or excluded from the backup process. USAGE
Usage: kbackup [Qt-options] [KDE-options] [profile] APPLICATION OPTIONS
Generic options: --help Show help about options --help-qt Show Qt specific options --help-kde Show KDE specific options --help-all Show all options --author Show author information -v, --version Show version information --license Show license information Arguments: profile Start with given profile Options: --script <file> Script to run after finishing one archive slice --auto <profile> Automatically run the backup with the given profile and terminate when done. --autobg <profile> Automatically run the backup with the given profile in the background (without showing a window) and terminate when done. --verbose In autobg mode be verbose and print every single filename during backup --forceFull In auto/autobg mode force the backup to be a full backup instead of acting on the profile settings AUTHORS
Kbackup was written by Martin Koller <kollix@aon.at>. This man-page was created by Scott Kitterman <scott@kitterman.com> and is licensed under the same terms as kbackup. 2010-07-13 kbackup(1)
All times are GMT -4. The time now is 06:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy