1

Imagine a directory structure that looks like :

/a1/b1/c1/O

/a1/b2/c2/O

/a1/b3/c3/O

how do I copy all content of the "O" directory to one file?

I've tried cp -r /a1/*/O ~/O and it fails

Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103
Mc Kevin
  • 962
  • 10
  • 31

1 Answers1

1

One more glob pattern needed. Use:

cp -r /a1/*/O/* ~/O

OR to make this command work for any depth use find:

find /a1 -type d -name 'O' -print0 | xargs -0 -I % cp -r %/* ~/O
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    +1, can you modify it to be insensitive to the depth of the directory? For example, it should work for /a1/b1/c1/d1/O and /a5/b5/c5/d5/e5/f5/g5/h5/O – Mc Kevin Sep 18 '14 at 08:07
  • Now that you mention about that, I found something similar: http://stackoverflow.com/questions/13236344/linux-command-output-as-a-parameter-of-another-command – Mc Kevin Sep 18 '14 at 08:11
  • Shouldn't the first command be `cp -r /a1/*/*/O/* ~/O` since the question says `O/` is 2 levels inside a1, not 1. – Chirag Bhatia - chirag64 Sep 19 '14 at 08:00
  • Yes that's correct, but I guess due to variable depth OP found `find` more suitable. – anubhava Sep 19 '14 at 08:04