Welcome to WebmasterWorld Guest from

Forum Moderators: bakedjake

A way to copy .htaccess files?

3:39 pm on Jun 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Well let me start by saying I don't do much command line work with *nix systems so I'm sure I'm missing something simple.

I have a directory that I want to copy over to many other directories.

I am using the following command sequence

cp -rRp * path/to/targetdirectory

Everything is copied and all permissions are preserved except for the .htaccess file. Is there an option I'm missing that will force cp to copy the .htaccess file as well?

Thanks in advance

5:53 pm on Jun 8, 2006 (gmt 0)

10+ Year Member

The -R option should have copied the .htaccess file. Are you sure it's not there? Try typing

ls -a path/to/targetdirectory

Does the .htaccess file show up that way? The -a option means "do not hide entries starting with .", so thought it might be worth a try.

1:33 am on Jun 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

no it's definitely not there.

I would have thought the -R option would have copied it as well, but it isn't for some reason.

if use

cp -rRp directory path/to/target

the htaccess file gets copied, but the original directory gets copied to the target directory as a subdirectory.

Any ideas anyone?

2:31 am on Jun 9, 2006 (gmt 0)

10+ Year Member

Are you copying into an already existing directory?

from man cp:

(Thus, if /a is a directory, then `cp -r /a /b' will copy /a to /b/a and /a/x to /b/a/x in case a directory /b existed already, but it will copy /a to /b and /a/x to /b/x if there was no /b beforehand, while it will fail in case there was an ordinary file /b.)

So, if you want to copy /pathtodirectory/original/ to /pathtodirectory/copy/, and /pathtodirectory/copy/ already exists, you're going to end up with /pathtodirectory/copy/original/

If you want the end result to be /pathtodirectory/copy/, with all of the files and directories under /original/ now under /copy/, /pathtodirectory/copy/ shouldn't exist before issuing the cp commnand.

Also, don't use the * as a wild card to copy the files, or else you won't get the hidden files.

cp -rRp /pathtodirectory/original/ /pathtodirectory/copy/
(where /pathtodirectory/copy/ does not previously exist)

Hopefully, someone far smarter and more knowledgeable than me will come along and show some method to recursively copy into an existing directory. I'm stumped.

3:26 am on Jun 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Yeah, the issue is I'm basically copying the setup for one domain into an addon domains folder.

so I have public_html/domainA and after setting up domain B I have the new folder.

I guess I could try either copying the files first and creating the directory before setting up the addon domain and also try setting up the addon domain, then deleting the folder and starting over.

Would definitely be nice if there was a way to copy the "." files to an existing directory. Everything else works perfectly.

10:48 pm on Jun 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Thats wired,tro to CP once again with -R option
1:20 pm on Jun 12, 2006 (gmt 0)

10+ Year Member

Whoo-hoo! I asked around and got the answer on another *nix oriented board.

cp -rRp /pathtodirectory/original/. /pathtodirectory/copy/

I tested it out on my laptop using "." instead of "*", and it copied unhidden and hidden files to an already existing directory. See if it works for you.


Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month