How to copy files from the folder without the folder itself
advanced cp
cp -r /home/username/A/. /usr/lib/B/
This is especially great because it works no matter whether the target directory already exists.
shell globbing
If there are not too many objects in the directory then you can use shell globbing:
mkdir -p /usr/lib/B/
shopt -s dotglob
cp -r /home/username/A/* /usr/lib/B/
rsync
rsync -a /home/username/A/ /usr/lib/B/
The /
at the end of the source path is important; works no matter whether the target directory already exists.
find
mkdir -p /usr/lib/B/
find /home/username/A/ -mindepth 1 -maxdepth 1 -exec cp -r -t /usr/lib/B/ {} +
or if you don't need empty subdirectories:
find /home/username/A/ -mindepth 1 -type f -exec cp --parents -t /usr/lib/B/ {} +
(without mkdir
)
If on a GNU system, from man cp
:
-T, --no-target-directory
treat DEST as a normal file
This allows you to write cp -rT /home/username/A/ /usr/lib/B/
to do exactly the right thing.
Tell cp
to copy the directory's contents and not the directory itself:
sudo cp -r /home/username/A/* /usr/lib/B/