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.

6 Answers 6


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/
  • 8
    the slashes make a difference! always suspected, never knew Commented Oct 31, 2017 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
    Commented Jun 9, 2018 at 11:13
  • My god... thank you for that nuance. I was wasting a lot of time trying to figure that out.
    – 2upmedia
    Commented Apr 15, 2020 at 19:58
  • 1
    also, just to add cp -rv * ar/ Will copy every folder, if the assumption is that you just simply want everything
    – the_5imian
    Commented Sep 25, 2021 at 3:27
  • @the_5imian How would you copy the contents of every folder using * Commented Jul 22, 2023 at 19:34

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.


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). Commented Sep 11, 2018 at 18:08

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> 

You must log in to answer this question.