13

After playing with multiple SQL and NoSQL databases over the years I feel the best way for me to ensure portability in my personal apps that are data-centric is to avoid all bonafide databases entirely. I see the file system as a beautiful database paradigm that is portable, human readable and thus has longevity that is sufficient for the type of personal applications I am writing. It's like a graph database that enforces a tree-structure (good for partitioning), with symlinks to represent many-to-one relationships.

Is there a way to export the whole file system topology as a single file? The output of a find command is promising, but there's no standardized way to export the data that indicates what a symlink points to. I don't want to come up with my own personal choice of find output format such as:

/home/me/photos/beach/me_and_my_dog.jpg -> /home/me/photos/beach/1.jpg

if someone has previously done the work of establishing a file system topology export format.

Another candidate is a JSON file:

home : [{
    me : [{
        photos : [{
            beach : [{
                1.jpg,
                { me_and_my_dog.jpg : ./1.jpg }
            }]
        }]
    }
}]

but again there are multiple ways of representing file types and I wonder if someone has already done the work of establishing a standard.

Note that I don't wish to export the contents of files - that would make the export much bigger than needed.

2 Answers 2

14

The output of the tree command seems to display what you're looking for:

.
└── photos
    └── beach
        ├── 1.jpg -> me_and_dog.jpg
        └── me_and_dog.jpg

Newer versions of the command will even output to HTML, XML or JSON.

XML Output:

<?xml version="1.0" encoding="UTF-8"?>
<tree>
  <directory name=".">
    <directory name="photos">
      <directory name="beach">
        <link name="1.jpg" target="me_and_dog.jpg"></link>
        <file name="me_and_dog.jpg"></file>
      </directory>
    </directory>
  </directory>
  <report>
    <directories>2</directories>
    <files>2</files>
  </report>
</tree>
2
  • 2
    Oh wow, that's exactly what I want. I was aware of the tree command (which is awesome) but I didn't realize it now supports parseable formats. Dec 20, 2014 at 0:19
  • 1
    NOTE: This tree command is the Linux version. The Windows version still only outputs the simple "tree".
    – Cole Tobin
    Dec 26, 2014 at 5:53
2

You can use mtree for this. See www.freebsd.org/cgi/man.cgi?query=mtree&sektion=8&manpath=FreeBSD+6.3-RELEASE and code.google.com/p/mtree-port

mtree -c

It is very versatile.

1
  • That's not JSON output as I personally prefer, but I'm sure Mac users will appreciate the fact it's built in. Dec 26, 2014 at 5:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .