0

I have a folder(A) which is structured like this

          Main Directory(A)
               |
               |
Subdir------Subdir2-----Subdir3
  |           |            |
  |           |            |
f0--f1      f0--f1       f0--f1

I want to copy and paste all files(recursively) in A to a new directory B. BUT I don't want to preserve the directory structure,i.e all files in A should be in B without any children directories.

2

Simple, in a shell :

$ find A -type f -exec cp {} B \;
5
  • Depending how many files you have there may be a noticeable performance gain by using the '+;' ending argument instead of '\;'
    – Jeff
    Apr 3 '19 at 22:12
  • If his version of find support it Apr 3 '19 at 22:13
  • 1
    Man you are fast Gilles!
    – Jeff
    Apr 3 '19 at 22:14
  • 2
    You should be aware that when two of your files have same names (e.g. f0--f1) the last one being copied will be the only one left. Apr 3 '19 at 22:16
  • @GillesQuenot It's at least standard syntax, so if it's not a really ancient implementation of find, it will support -exec ... {} +. The real issue with that is that you would have to use GNU cp: -exec cp -t B {} + (the {} has to be last, just before the +), but since this is Linux, that should not be an issue.
    – Kusalananda
    Apr 4 '19 at 6:24

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.