Is there a better way on the command line to essentially accomplish the following but with a single command
cp -r css/ ar/
cp -r images/ ar/
cp -r js/ ar/
cp -r backups/ ar/
I've just been stringing them together with a semicolon.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityCopying folders into another folder (folder in folder):
cp -r css images js backups ar/
Note: this is different from copying just the contents themselves(contents of folders in folder):
cp -r css/ images/ js/ backups/ ar/
cp
is not rsync
. however cp -r css/. images/. ar/
does copy the contents without the directories. my cp version is "cp (GNU coreutils) 8.29".
Jun 9, 2018 at 11:13
I am on Ubuntu 18.04.3
and use the following command to copy multiple folders in one directory:
cp -r /source_directory/{folder1,folder2,folder3} /destination
Equals
cp -r /source_directory/folder1 /destination
cp -r /source_directory/folder2 /destination
cp -r /source_directory/folder3 /destination
I think it's a very clean method.
The answer is simple, and it works on Debian "this is actually how i did it" (tested) lets say you're in /etc and want to copy some files and folders before you format your hard disk (for some reason) you'd type the following and everything mentioned below will be copied to /mybackups/ folder:
sudo cp -r -a apt/ bash.bashrc environment hosts init.d/ init/ nginx/ proxychains.conf sudoers sysctl.d/ profile.d/ grub.d/ /boot/grub/ /opt/ /root/ /var/www/ /mybackups/
as you can see above, i tried to copy folders from outside etc as well by pointing to its location like /boot/grub/ or /opt/ and it worked!
if you want to copy all the folder's in a directory into another folder.
cp -r * /anotherfolder/
if you want to copy some files or folders.
cp -r folder1 folder2 folder3 /anotherfolder
cp -r css images js backups ar/ should work, Note that in order to copy a directory on Linux, you have to execute the cp command with the r recursive option.
You can't copy two directories using cp
command alone.
You can copy recursively using -r
option though.
For example:
cp -r <source> <destination>