1

I tried to combine --dirsfirst and -r, but directories still show up on top, only in reverse alphabetical order. It seems like -r is applied first, which is also indicated by the man pages.

Any other ideas of how I would go about sorting the output of tree so that subdirectories are listed after the files?

3
  • 1
    try simple 'tree -r'
    – VenkatC
    Nov 13, 2015 at 1:20
  • That will just reverse the alphabetical order. Nov 13, 2015 at 1:23
  • nvm, I understood your question better now
    – VenkatC
    Nov 13, 2015 at 1:57

1 Answer 1

3

If you use tree -r, then reverse all lines, e.g., using tac and translate the box-characters it looks reasonable:

#!/bin/sh
tree --dirsfirst -r | tac | sed -e 's/\d226\d148\d148/\d226\d148\d140/'

# 0x2514 is lower-left-corner,
# 0x250c is upper-left-corner
# 0x2514: 9492 022424 0x2514 text "%\024" utf8 \342\224\224
# 0x250c: 9484 022414 0x250c text "%\014" utf8 \342\224\214

I got the Unicode value using the character-identifier in vi-like-emacs, and the UTF-8 equivalent using my hex utility.

Here's the end of my /etc directory, to illustrate:

├── xdg
│   ┌── catalog
│   ├── catalog.old
│   ├── docbook-xml.xml
│   ├── docbook-xml.xml.old
│   ├── docbook-xsl.xml
│   ├── docbook-xsl.xml.old
│   ├── rarian-compat.xml
│   ├── sgml-data.xml
│   ├── sgml-data.xml.old
│   ├── xml-core.xml
│   ├── xml-core.xml.old
│   │   ┌── CatalogManager.properties
│   ├── resolver
├── xml
│   ┌── includes
│   ├── xpdfrc
├── xpdf
│   ┌── newuser.zshrc.recommended
│   ├── zlogin
│   ├── zlogout
│   ├── zprofile
│   ├── zshenv
│   ├── zshrc
├── zsh
.

For reference:

UTF-8 encoding table and Unicode characters page with code points U+2500 to U+25FF

2
  • Thanks, is there an easy solution to make the output look the same as from tree? E.g. I would still like the files in subdirectories to be listed under the subdirectory rather than above it. So the small "tree-branches" would protrude downwards instead of upwards. Nov 14, 2015 at 1:30
  • I don't think there is an easy solution (aside from modifying 'tree'). Nov 14, 2015 at 1:46

You must log in to answer this question.

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