Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .