Re-constructing directory structure on Linux

If ever you need to re-construct the directory structure on Linux/Unix on a different machine you can just run this command.

# Generates a list of mkdir commands to re-construct the directory structure from current location

find . -type d| while read -r line; do echo “mkdir -p $line”; done

If you are wanting to copy files as well, just use scp or rsync

The use case for these kind of commands nowadays is greatly reduced, if you are using DevOps tools such as puppet or chef, they will do this kind of thing automagically out-of-the-box. If you are running your databases on VMs (datafiles within the VM), most of the time you could clone the image and everything is the same.
The aim of all those tools is to make the job of Sysadmins and DBAs easier whilst producing a environment where the state is consistent/known.

Have Fun


One thought on “Re-constructing directory structure on Linux

  1. rather than using scp -r or rsync I tend to just use tar over ssh.

    For example I have /app/foo and want it on the second server as well, I just do
    tar c /app/foo | ssh otherserver 'tar -C / -x'

    If the network is slow and cpu load is not an issue I add parameter 'z' for on-the-fly compression/decompression.

Comments are closed.