bashtree

Creating directories and files from TREE command output


I've used a tree command to list recursively about a hundred folders with some 150 files in them. This tree output is saved in a file.

How can I parse this file via bash and recreate these files and folders on a different computer?

Note that I don't need to copy these files. All I need is just the same naming convention on another computer where some custom work will be done.


Solution

  • find will do what you want, something like

    find /my/pathto/blah -type d | sed -e "s/^/mkdir -p /g" > commands
    find /my/pathto/blah -type f | sed -e "s/^/touch /g" >> commands
    

    The first find will create the instructions to make the directories. The second find will create the instructions to create empty files.