12

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.

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
    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. – Sridhar-Sarnobat Dec 20 '14 at 0:19
  • 1
    NOTE: This tree command is the Linux version. The Windows version still only outputs the simple "tree". – Cole Johnson Dec 26 '14 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.

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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