Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to copy a folder structure (without the files), but only the top level folders. That is, with my source:

folder a
 * folder 1
 * folder 2
   * folder X
folder b
 * folder 3
folder c

I want my destination to simply be:

folder a
folder b
folder c

How can I do this in Linux?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

With GNU find, which supports -printf, and GNU xargs, which supports -r:

find /source/path -mindepth 1 -maxdepth 1 -type d -printf '/target/path/%f\0' | xargs -r -0 -- mkdir --
share|improve this answer

You could simply do this:

for dir in *; do mkdir /path/to/"$dir"; done

This assumes that you want to copy everything in the current directory and that all you have in that directory are the target folders, no files. It will collect all names in the current directory (*) and run mkdir to create empty folders of that name in the target path.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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