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.


Copying 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/
  • 5
    the slashes make a difference! always suspected, never knew – Peter Perháč Oct 31 '17 at 9:36
  • 2
    slashes don't make a difference in my testing. 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". – sourcejedi Jun 9 '18 at 11:13
  • My god... thank you for that nuance. I was wasting a lot of time trying to figure that out. – 2upmedia Apr 15 '20 at 19:58

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!

  • 1
    I believe -r there is not needed, as -a already contains it (via: man). – David Potočnik Sep 11 '18 at 18:08

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


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.


You can do this:

cp -r css images js backups ar/ -v

Adding -v (verbose flag) will show you the progress.


You can't copy two directories using cp command alone.

You can copy recursively using -r option though.

For example:

cp -r <source> <destination> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy