Per the answers here I'm able to list the contents of my tarball in ls format. However, I'd like to be able to list them in tree format, i.e. something like the latter instead of the former:

With tar:

$ tar -tf foo.tar 

With tree:

$ tree foo
├── bar
│   ├── myfile.txt
│   └── yourfile.txt
└── baz
    └── qux
        └── hisfile.txt

Is it possible to do this without extracting the tarball? I'd prefer to have to avoid extracting the tarball due to their size.

2 Answers 2


Several scripts exist for converting a list of path names into tree form:

All these scripts work with tar -tf … output; for example:

$ tar -tf foo.tar | treeify
 │  ├─myfile.txt
 │  └─yourfile.txt


$ bsdtar -tf foo.zip | treeify
$ find /dir -size +5 | treeify
$ git ls-files       | treeify
$ pacman -Qql foopkg | treeify
$ unrar vb foo.rar   | treeify
$ zipinfo -1 foo.zip | treeify
$ gsettings list-schemas   | treeify -s. -f
$ qdbus | sed -n "s/^ //p" | treeify -s. -f
$ ldns-walk netbsd.org | awk '{print $1}' | treeify -s. -f -R

This is just an addendum to user1686's answer though I do not have enough reputation to comment. While his scripts certainly do the job well they need to be downloaded while tree can actually do this natively:

$ tar tf foo.tar | tree --fromfile .
└── foo
    ├── bar
    │   ├── myfile.txt
    │   └── yourfile.txt
    └── baz
        └── qux
            └── hisfile.txt

4 directories, 3 files

Note that unlike most tools tree uses a dot . and not a dash - to read input from stdin:

        Reads a directory listing from a file rather than the file-system.
        Paths provided on the command line are files to read from rather than directories to search.
        The dot (.) directory indicates that tree should read paths from standard input.

This allows one to use the typical tree functions like wildcards though sizes obviously cannot be shown and the level argument (-L) apparently also does not work...

  • Awesome! FYI this works for the output of pkgutil too: pkgutil --payload-files OpenJDK17U-jdk_aarch64_mac_hotspot_17.0.7_7.pkg | tree --fromfile .
    – Wes
    Jun 15, 2023 at 19:16
  • Which version of tree is this with? My Tree 1.7.0 by Steve Baker has no option --fromfile. linux.die.net/man/1/tree
    – Rovanion
    Sep 20, 2023 at 9:50
  • I am running version 2.1.0 locally though based on the tree manpage from Ubuntu 20.04 LTS it seems to be present since 1.8.0
    – Septatrix
    Sep 20, 2023 at 22:28

You must log in to answer this question.

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