[Gllug] cp command

Stuart Sears stuart at sjsears.com
Wed Nov 29 09:20:36 UTC 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Andrew Black wrote:
> John G Walker wrote:
>> To copy the contents from subdirectory A into subdirectory B: cp
>> ,/A/* ./B
> 
> I have some questions and observations - this doesnt copy files that
> start with .  - how can you get it to do this?

see below

> - a -v option might be useful to display what you are doing - it
> assumes that directory B exists (otherwise it tries to write to a 
> file called B, and fails if there is more than one file in A). - what
> is the difference between using ./A and plain A ?

very little.

alternatively, to include all the dotfiles and preserve perms and all the
other bits, you might consider rsync. Although for an original copy it
is slower than cp, it has many cool features.

rsync -avP dir/ destination-dir
Will copy the *contents* of dir/ to destination-dir.

where
- -a = archive  - preserve timestamps, owner, group etc. also copies
     symlinks as symlinks.
- -v = verbose
- -P = show progress - generates much more output. You may not like this.
     I sometimes find it helpful.


Bear in mind that the trailing slash on dir/ is required if you don't
want to copy the dir. rsync will copy everything after the last / on
the source path. (with these options at least!).
It will create the destination directory for you if it doesn't exist
already.

failing that, copying all dotfiles as well as normal files requires you to
tell bash that it is okay to include these files in filename globs, which
is a shell option:

shopt -s dotglob
cp -av A/* B/

to turn it off again
shopt -u dotglob.

Regards

Stuart
- --
Stuart Sears RHCA RHCSS RHCX PEBKAC STFU
"Quit worrying about your health. It'll go away."
- - Robert Orben
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFFbVDkamPtx1brPQ4RAtNyAJ4kKvqYNIhUMNaYrpXCp5upwxZc4gCeKtsL
x3KdUQyGC+SpC/pet24C280=
=lqGV
-----END PGP SIGNATURE-----
-------------- next part --------------
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug


More information about the GLLUG mailing list