Report this

What is the reason for this report?

How to copy folder structure

Posted on January 10, 2020

I want to recreate my folder structure without copying the current files in the folder.

Is this possible with somesort of a command or should I do it manually folder by folder?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi @fkutev,

You can use just the find command. Here is how I would do it

find . -type d > dirs

Once you have your directories in the dirs file, you can make execute the following command to actually create them

xargs mkdir -p < dirs

This will create the directories you wish.

Regards, KDSys

I’ve just found out a small bug in the above commands. If you have spaces in your directory names, the above won’t work properly.

In such a case, you can actually use the following :

find . -type d -print0 >dirs

As soon as the above has finished execute :

xargs -0 mkdir -p <dirs

Regards, KDSys

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.