1

Is there a Linux utility for creating templates for directory structures, outside of the scripts packaged with a DE like Gnome or LXDE? (I run openbox and would like to avoid a DE at all costs)

There is this post talking about template files, which I will absolutely use, and there is the template toolkit but that's more for documents and dynamic web content (although, it can be easily extended).

I'm looking for something to encompass whole directory structures as well.

Say I have a C template directory structure like so:

prj_?\    
    Doxyfile
    Makefile
    README
    bin\
    data\
    doc\
    include\
    src

Or a nodejs template structure like:

index.html
js/
    main.js
    models/
    views/
    collections/
    templates/
    libs/
        backbone/
        underscore/
        ...
css/
...

Surely there must be something available, given that folders like /skel exist... or is that yet another manually scripted section of Linux?

If this doesn't yet exist, I would love to contribute to the community by writing and maintaining a tool of this nature, or at the very least writing a vim plugin to handle such functionality (spoiler alert: doesn't exist), but that would be something to discuss on the vim exchange.

  • I suspect a shell script with a mkdir -p call is common. Unclear what the advantage over that would be; could you clarify a little what you envision? – derobert Jan 7 at 18:14
  • yeh sure... I mean, calling mkdir -p for every single differing template would just be laborious and essentially repeated work. By the same token, as you mentioned, this would be a fairly common thing that many people would do hence a small tool with some config file options would be helpful. I would envision a small CL tool, with definitions for file types. I could imagine a syntax like <command> <filetype i.e. C, HTML etc> <directory>. I would add hooks functionalities for git and vim, and config files could be in yml or json. – BitShift Jan 7 at 18:20
  • Well, you save the mkdir -p line in a script file, so you don't ever have to retype it. You're basically just passing it a list of directory names, so hard to get shorter than that. Or alternatively, you have a built-out directory tree and want to duplicated it, but that's what cp -r does. (/etc/skel, BTW, at least on Debian is implemented by account creation script adduser, a perl script — it just copies the files in a rather weird way, probably it can't depend on File::Find being available). Catalyst (perl MVC framework) does have its app setup script, which does something similar... – derobert Jan 7 at 18:25
  • yeh I figured as much... that's cool, just wanted to see if I was missing something obvious. I'll definitely have a dig through useradd/adduser (Arch/Debian) and see what I can make of perl. Thanks for clarifying! :) – BitShift Jan 7 at 18:33
2

The mtree(1) utility is standard on BSD systems, and I'm pretty sure it ought to be available for Linux as well somewhere. It reads a directory hierarchy specification and compares it with what's found on disk, optionally deleting files (or updating their permissions or ownership) and creating missing directories as needed.

Its specification does not quite look like what you have. The specification for an /etc directory, as found on an OpenBSD base system, would look like

/set type=dir uname=root gname=wheel mode=0755
.
    etc
        X11
            app-defaults
            ..
            twm
            ..
            xenodm
                pixmaps
                ..
            ..
            xinit
            ..
            xsm
            ..
        ..
        fonts
            conf.avail
            ..
            conf.d
            ..
        ..
    ..

That would be the tool for creating empty directories (mtree -d -u -f spec_file or something similar). If you want to create something like a populated directory hierarchy from some skeleton directory, I would use a tar archive of the skeleton directory and just unpack that at the destination.

An existing skeleton directory can be copied with pax easily:

( cd -- "$skel_dir" && pax -rw -p p . "$dest_dir" )
  • 1
    Heck to the yes my dude, this is exactly what I'm looking for... you legend!! – BitShift Jan 7 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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