[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Help with command - cp



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On 2014-01-29 10:43, berenger.morel@neutralite.org wrote:
> 
> 
> Le 26.01.2014 15:26, Lisi Reisz a écrit :
>> 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
>> 
>> Thanks, Lisi
> 
> Just a note, too late but it could help later too, for another
> problem.
> 
> What I would have made is a quick and dirty method: first a classic
> copy ( I do not know rsync too ) $cp -r ~/foo ~/bar
> 
> And then: $ cd ~/bar && rm `find -name '.*'`

Find is indeed very useful, but that's probably a bad idea.  You'll
get into trouble with filenames containing spaces for example.  find
will also (as you point out) try to remove the current directory
('.').  And you won't remove hidden directories because you didn't
call rm with '-r', which is a good thing since it would have removed
said current directory.

If you really want to use find, use something like:

$ find -depth -name '.?*' -exec echo rm -rv -- {} \;

Which will not match '.' because it expects at least one character
after the dot, will handle filenames correctly, and remove directories
recursively.  Once you remove the 'echo' of course.  I left it in
there so you can run it to see what would be removed.

Of course, in this case you should probably use rsync instead.

> Indeed, it have really poor performances (in term of computer
> ones), since some files are first copied and then deleted, but it
> should work ( did not tried, actually ) and does not require any
> learning except the very basic use of find, in case you do not
> already know it. Could be made in a better way of the same
> direction, maybe by using find to select stuff to copy, but I take
> for sure that the lines will be quite more complex, as find is a
> really powerful tool, but it's man is not really clear about how to
> do stuff which could be considered basic. I can remember having
> some pain with it for more complex things like excluding some
> directories and only selecting files with different extensions.
> 
> Note that folders . and .. can not be removed so you will warnings,
> but those are simply warnings.
> 
> This is just another (and a dirty one) way to do the thing you
> needed :)


- - Felix
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
Comment: Using GnuPG with Icedove - http://www.enigmail.net/

iQIcBAEBCgAGBQJS6RGLAAoJELIY/ywn/GzGPfwQALH7Rslw4LWZyOrR71hqXq0T
y+XWTHS6eDVZDgn8JCh70Bky+DHvvYuqpu+VerJec0BKZSXz5OU+YeDY3wELp+AR
TXPt5/7wgrxATspi1t356kWx47Cp0BOmS3AX/16fStV4tQ5YX6r/bCUKUMbtVlU7
bHozq0L0iFi6rysnvZFWZpeZIDTFqo7BTRs05ggd/iuWZALm3eYlbsQJ2ep7gb2H
yrAvt0wy1pTN8vGjtZiZcIqy9CHhNXJ7w3qAz0TLrAJ3+KvpDmMiJxq+a2dPc4Nu
rJAmJFu6YX1hEzTpCV73vV/i7xTI11zJISnxS3QPdaawpNsI0wbAQNv0x6xmZyVo
8Bw7Gr26/LJm7N18cyknSKCEoenCOP6I/Q1sijkloORMWE9uA8s+5BLBYLvXXrsT
XjuTTYg8igpy/h6d4Cl1XjZRtJnC1zmDZwGRep6OCwzw9qNGwyq9Xy+0vn9CzJ+P
y4U5YKDjHWC3NHdrOCZp1Kajo2viZDZ3KMz5t7hh3RIwpcwkdTjCiq/bea3rDAqv
rClMVRKqz65uGNNqiTmnguSb0gSDtfaEWshpGv9em5DUyArp+NZR9ZTn+ggLyOi/
tnrs6zTAuth9gnplVWgFQtmvJ9oBLHLqwHlGxbeqd9IWqiLhik2iMcOPMvwGYukf
TVe/Kf5MUp0Gi6e5aYvO
=bvG0
-----END PGP SIGNATURE-----


Reply to: