Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

HI all,

Is there a linux command which will output the structure of a given directory as XML? if there is, that would be awesome.

Thanks very much

share|improve this question
That sounds like it wouldnt be too tough to implement upstream, you should consider adding an extension to the tree command or ask the maintainer to do it for you: might not be a solution for right now but it may help someone else down the line. If you don't write it I will, cus its a good idea! – Andrew Bolster May 12 '10 at 11:33
Hi Andrew, Yes, this exactly what i've been thinking. I looked at the 'tree' command before I posted the question. I was surprised there was not an option on the command like tree /tmp --xml or something similar. Alas, i'm not too familiar with C (i presume it's written in that) so I would struggle to write it but by all means if you can (and of course if you have the time to do so) then that would be AWESOME. Thanks. – Jamie May 12 '10 at 16:07
up vote 0 down vote accepted

XMLStarlet will do this.

xml ls

share|improve this answer

You can do this by using 'tree' command.

tree -X <dir>
share|improve this answer
tree --help for all options (HTML output, etc) – Abram Dec 11 '15 at 15:22

As far as I know there is no standard linux command to do the job, but google-ing I found that there is a free multi platform: xml-directory-listing

Unfortunately it is written in Java.

share|improve this answer
Hi Albert, Thanks. I will give it a go and report my findings :-) – Jamie May 12 '10 at 7:54

You could easily write a script for that, using languages such as Perl, Python or Ruby should do well.

share|improve this answer

protected by Chris S Jun 11 '13 at 14:10

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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