You are not logged in.

#1 2005-01-01 17:01:21

Pajaro
Member
Registered: 2004-04-21
Posts: 884

is that easy to copy a dir?

Is this the only way to copy a dir including hidden files it can contain?

for i in $(find -name "/source/dir/.*"); do cp $i /dest/dir/ -a; done

"cp -a" does not copy hidden files.

Offline

#2 2005-01-01 17:22:40

MaceM
Member
From: Austria
Registered: 2003-11-26
Posts: 47

Re: is that easy to copy a dir?

cp -r old-directory new-directory
Recursive, copy directory and all subdirs.

doesn't work?

Offline

#3 2005-01-01 17:26:45

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: is that easy to copy a dir?

"cp -a" is an extension of "cp -r"

"cp -a" = "cp -dpR"
-d = don't follow symlinks
-p = preserver ownership
-R = -r = recursively

and no, it does not copy hidden files.

Offline

#4 2005-01-02 02:24:37

skoal
Member
From: Frequent Flyer Underworld
Registered: 2004-03-23
Posts: 612
Website

Re: is that easy to copy a dir?

Pajaro wrote:

[..]and no, it does not copy hidden files.

Huh? "cp -a" copies hidden directories (those with ".") just fine for me.  I use it all the time.  Are you using an alias or something instead?

Hell, I just backed up a user directory with "cp -a /home/user /tmp".  All "." subdirectories are there.  No problem.

Offline

#5 2005-01-02 03:00:38

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: is that easy to copy a dir?

i've created a directory with a hidden dir and a hiddne file. it has been succesfully copied... I don't know what happens. I'll check it again next time i copy a dir.

Offline

#6 2005-01-02 03:10:04

skoal
Member
From: Frequent Flyer Underworld
Registered: 2004-03-23
Posts: 612
Website

Re: is that easy to copy a dir?

Pajaro wrote:

i've created a directory with a hidden dir and a hiddne file. it has been succesfully copied... I don't know what happens. I'll check it again next time i copy a dir.

Anything's always possible.  It might very well be that using wildcards while using "cp -a" might have some effect on hidden directories.  There's always a way to misuse a system command.  I do it all the time, sometimes on purpose.  Also, more than likely, you probably didn't have the proper permissions on some of those subdirectories.  That's always a possibility, especially if the "other" field is "---", and you're neither owner or part of the group.

Offline

#7 2005-01-02 03:30:11

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: is that easy to copy a dir?

I did it as root: I was moving my opt dir into another hd. So I don't think permissions are the cause of it

Offline

#8 2005-01-02 12:19:00

mico
Member
From: Slovenia
Registered: 2004-02-08
Posts: 247

Re: is that easy to copy a dir?

How did you copy the source?

cp -R sourcedir destdir
or
cp -R sourcedir/* destdir

The first one is correct and should copy also hidden files and dirs, the second wrong, because bash parses the wildcard before passing args to cp and hidden files are excluded this way.

Offline

#9 2005-01-02 13:01:14

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: is that easy to copy a dir?

I did the second.

wow, I'd never imagined that this would apply to all hidden files at any directory level after the first.

So next time I'll run

cp -R . /desdir/

thanks

Offline

Board footer

Powered by FluxBB