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?
-
1try simple 'tree -r'VenkatC– VenkatC2015年11月13日 01:20:18 +00:00Commented Nov 13, 2015 at 1:20
-
That will just reverse the alphabetical order.joelostblom– joelostblom2015年11月13日 01:23:17 +00:00Commented Nov 13, 2015 at 1:23
-
nvm, I understood your question better nowVenkatC– VenkatC2015年11月13日 01:57:20 +00:00Commented Nov 13, 2015 at 1:57
2 Answers 2
If you came here looking for this answer (as I did), use:
tree --filesfirst
Option --filesfirst
was added in version 2.0.0 (12/21/2021)
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
-
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.joelostblom– joelostblom2015年11月14日 01:30:57 +00:00Commented Nov 14, 2015 at 1:30
-
I don't think there is an easy solution (aside from modifying 'tree').Thomas Dickey– Thomas Dickey2015年11月14日 01:46:25 +00:00Commented Nov 14, 2015 at 1:46