If I want to copy a hierachy of files and directories which include a lot of hidden files (and directories) i.e. ones which start with '.' what is the easiest way to go about it?
I know one approach is to use tar but it would be easier if I could simply 'cp -R x y' and copy *everything* in x to y. Is there not a simple way to do this?
On Sat, Oct 14, 2006 at 10:02:04PM +0100, cl@isbd.net wrote:
If I want to copy a hierachy of files and directories which include a lot of hidden files (and directories) i.e. ones which start with '.' what is the easiest way to go about it?
I know one approach is to use tar but it would be easier if I could simply 'cp -R x y' and copy *everything* in x to y. Is there not a simple way to do this?
rsync -a x/ y/
(there /s are reasonably useful, and make it slightly more predictable if the destination directory already exists)
Cheers,
On 14-Oct-06 cl@isbd.net wrote:
If I want to copy a hierachy of files and directories which include a lot of hidden files (and directories) i.e. ones which start with '.' what is the easiest way to go about it?
I know one approach is to use tar but it would be easier if I could simply 'cp -R x y' and copy *everything* in x to y. Is there not a simple way to do this?
I think the way to do it (but there are traps, which this method tries to avoid) is
cd x cp -a * .[^.]* full_path_to_y
This does two things:
1. The 'cd x' avoids x itself being created as a subdirectory of y with everything under x being copied to y/x/....
2. In "cp -a * .[^.]* full_path_to_y", the "*" matches non-hidden files (i.e. don't start with ".") and the ".[^.]*" excludes the directory x/.. (which would cause everything below the parent directory of x to be copied!).
I've just tested this with two test directories
~/Test1 ~/Test2
with ~/Test2 initially empty, and
ls -aR Test1 Test1: . .. a .a .A b .b c .c d .d
Test1/.A: . .. a .a b .b c .c d .d
so there's a mixture of hidden and visible files in Test1, and a hidden directory .A with a similar mixture.
After
cd Test1 cp -a * .[^.]* full_path_to_y cd ..
I find that ls -aR Test2 gives:
ls -aR Test2 Test2: . .. a .a .A b .b c .c d .d
Test2/.A: . .. a .a b .b c .c d .d
which is identical to Test1.
But I suggest you test this for yourself, and see if it does exactly what you want! (It's tricky).
Best wishes, Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 14-Oct-06 Time: 22:34:48 ------------------------------ XFMail ------------------------------
Sorry -- owing to lazy mouse-copying I made a mistake below.
On 14-Oct-06 cl@isbd.net wrote: If I want to copy a hierachy of files and directories which include a lot of hidden files (and directories) i.e. ones which start with '.' what is the easiest way to go about it?
I know one approach is to use tar but it would be easier if I could simply 'cp -R x y' and copy *everything* in x to y. Is there not a simple way to do this?
I think the way to do it (but there are traps, which this method tries to avoid) is
cd x cp -a * .[^.]* full_path_to_y
This does two things:
1. The 'cd x' avoids x itself being created as a subdirectory of y with everything under x being copied to y/x/....
2. In "cp -a * .[^.]* full_path_to_y", the "*" matches non-hidden files (i.e. don't start with ".") and the ".[^.]*" excludes the directory x/.. (which would cause everything below the parent directory of x to be copied!).
I've just tested this with two test directories
~/Test1 ~/Test2
with ~/Test2 initially empty, and
ls -aR Test1 Test1: . .. a .a .A b .b c .c d .d
Test1/.A: . .. a .a b .b c .c d .d
so there's a mixture of hidden and visible files in Test1, and a hidden directory .A with a similar mixture.
After
cd Test1 #### cp -a * .[^.]* full_path_to_y #### NO!!! cp -a * .[^.]* ../Test2 cd ..
I find that ls -aR Test2 gives:
ls -aR Test2 Test2: . .. a .a .A b .b c .c d .d
Test2/.A: . .. a .a b .b c .c d .d
which is identical to Test1.
But I suggest you test this for yourself, and see if it does exactly what you want! (It's tricky).
Best wishes, Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 14-Oct-06 Time: 22:53:58 ------------------------------ XFMail ------------------------------
On Sat, Oct 14, 2006 at 10:02:04PM +0100, cl@isbd.net wrote:
If I want to copy a hierachy of files and directories which include a lot of hidden files (and directories) i.e. ones which start with '.' what is the easiest way to go about it?
I know one approach is to use tar but it would be easier if I could simply 'cp -R x y' and copy *everything* in x to y. Is there not a simple way to do this?
rsync -av /path/to/foo /where/you/want/it/to/go
Adam
cl@isbd.net wrote:
If I want to copy a hierachy of files and directories which include a lot of hidden files (and directories) i.e. ones which start with '.' what is the easiest way to go about it?
I know one approach is to use tar but it would be easier if I could simply 'cp -R x y' and copy *everything* in x to y. Is there not a simple way to do this?
Here's a snippet from the doc I keep with useful stuff in it:
#### To copy files with tar cd fromdir; tar cf - . | (cd todir; tar xfBp -)
copy all files and subdirectories in "fromdir" to "todir". Note target dir must exist. Note the use of "-" with pipe. N.B. this is how you move a directory between discs.
Cheers, Laurie.