Re: Help with command - cp
On Sunday 26 January 2014 14:49:31 Felix C. Stegerman wrote:
> 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?
>> :--
> > cp -Rp /path/to/sourcedir/A/* /path/to/destinationdir/B
>
> Not quite. But close. You can get in trouble depending on how
> many items are in A and whether or not B exists. And it will only
> ignore hidden files if they are in A directly, not if they are in
> subdirectories.
>
> I prefer using rsync instead:
>
> $ rsync --dry-run -av --progress --exclude='.*' /path/to/A/
> /path/to/B/
>
>
> Notes:
>
> * Existing files in B will be overwritten.
> * You may want to look at the manpage to see what the options do.
> * The slashes after A and B are important.
> * The --dry-run option will show you what the command will do
> without actually performing the copy -- so you can check whether it
> behaves as expected. Leave it out to actually perform the copy.
> * You can add the --delete option if you want to completely
> synchronise the directories, as it will cause removal of files in B
> that are not in A (except those excluded -- see the man page).
> * If you only want to exclude hidden files in A itself (not in
> subdirectories), use --exclude='/.*' instead.
Thank you, Felix. That is very helpful and clear. Your notes are
very useful.
As I said to Zenaan, it is obviously time for me to bite the bullet of
rsync. It seems a significantly better tool for the purpose than cp.
Lisi
Reply to: