Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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've seen an app for Mac called Structurer (here a video which given a structure of files and folders like this:


will create this files and folders in a existing place.

There is something like that for Ubuntu, or how can i build a shell script to get something like this?

If is possible would be cool also to be able to create files using templates.

share|improve this question

The tricky part is that you have files and folders shown the same way, and no simple way to tell them apart. For file 2.1 there is not a way to tell if it (/folder2/folder2.1/file2.1) is actually a folder or a file within folder2.1.

Yes your description says the word *file* so we know you mean file, but to a program how could it tell? A program might tell files from paths because one is followed at the same indentation level with another entry. BUT, that leads to a set of complicated and confusing rules.

I would suggest you use a keyword or just full qualified names. The easiest is:






The trailing slash means "This is a folder and not a file." Then you can have an easy script like this to create your directory structure. A couple warnings about this script.

  1. the higher level directories must be created first.
  2. I prepend a "." to the path so all directories created are relative to the one in which the script is run.
  3. I do no error checking for the content of the dir/path file.
#!/bin/sh -v
# builds a directory and file structure.
# directories must exists before referenced or file in the directory declared.
# sample input looks like (without the leading #):
# /folder1/
# /folder2/
# /folder2/file1
# /folder2/folder2.1/
# /folder2/folder2.1/file2.1
# make sure we have our one and only input parameter.
if [ $# != 1 ]; then
        echo "Usage: `basename $0` input_file_name"
        echo "input_file_name contains absolute dir paths with a trailing slash,"
        echo "or absolute file path/name with no trailing slash."
        exit 1

# get the file name from the command line

# make sure the input parameter specifies a file.
if [ ! -e ${FILE} ]; then
        echo "Sorry, the file ${FILE} does not exist."
        exit 1

for LINE in $(cat $FILE)
        LAST=$(echo ${LINE} | awk -F/ '{print $(NF)}')
        # if file ends with a slash, this value is blank, if it is no slash, this is the file name.
        if [ "${LAST}XXX" = "XXX" ]; then
                # is empty, so it is directory, future feature to check exist already
                mkdir ".${LINE}"
                # is not empty, so it is a file
                touch ".${LINE}"
exit 0

This will create the directories and files as shown in the input file. If the script is called and you have chmod 755 then the command ./ data will generate your directories and files as described in the data file.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.