1

I have a directory ~/dir that contains a bunch of random folders like: ~/dir/av 801 and ~/dir/lm 320. I want to copy the contents of every inner folder (ie: av 801) into a different directory. The contents of that folder can consist of folders or files.

This is what I guessed the bash command would be:

cp ~/dir/*/* ~/target/

But it gives this error:

cp: when copying multiple files, last argument must be a directory

Is there a bash command that can do such a thing?

Korey Hinton
  • 160
  • 8

1 Answers1

1

To copy directories, you need to tell cp to copy recursively by passing it the -r flag.

cp -R ~/dir/*/* ~/target/

If ~/target does not exist, you need to create it first.

mkdir ~/target
  • that worked, except I was using eshell and I had to use a capital R for some reason: cp -R ~/dir/*/* ~target/ – Korey Hinton Jul 01 '13 at 21:52
  • Apparently `-r` is [not portable](http://unix.stackexchange.com/questions/75904/are-fifo-pipe-unix-domain-socket-the-same-thing-in-linux-kernel) while `-R` is.. I have modified my answer to reflect that. –  Jul 01 '13 at 21:58
  • Evan, did you mean to link to [-r is not portable](http://unix.stackexchange.com/questions/18712/difference-between-cp-r-and-cp-r-copy-command/18718#18718)? – Korey Hinton Jul 01 '13 at 22:05
  • Yes. I pasted the wrong link. –  Jul 01 '13 at 22:09