Re: Help with command - cp
* Felix C. Stegerman wrote on 2014-01-26 at 15:49 (+0100):
> On 2014-01-26 15:26, Lisi Reisz wrote:
> > I am wanting to use the CLI to copy some files from dirA to
> > dirB. I want to exclude all hidden files. Will this command
> > achieve it?
>
> I prefer using rsync instead:
>
> $ rsync --dry-run -av --progress --exclude='.*' /path/to/A/ /path/to/B/
>
> * The slashes after A and B are important.
No, you only have to take care about the trailing slash of the
source A. See rsync(1):
A trailing slash on the source changes this behavior to avoid
creating an additional directory level at the destination.
You can think of a trailing / on a source as meaning "copy
the contents of this directory" as opposed to "copy the
directory by name", but in both cases the attributes of the
containing directory are transferred to the containing
directory on the destination. In other words, each of the
following commands copies the files in the same way,
including their setting of the attributes of /dest/foo:
rsync -av /src/foo /dest
rsync -av /src/foo/ /dest/foo
The trailing slash of the target directory B is irrelevant:
$ mkdir -p foo/dir
$ touch foo/file foo/dir/file foo/.hidden foo/dir/.hidden
$ rsync -av --exclude='.*' foo target1
$ rsync -av --exclude='.*' foo target2/
The results are identical directories ./target1 and ./target2.
Of course, both need not exist.
Regards,
Mathias
Reply to: