How to copy folder structure

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?

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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

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