Can a file system's logical structure (including symlink targets) be represented in a single lightweight file (non-binary)?

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.


Solution 1:

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>

Solution 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.