16

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 
foo/
foo/baz/
foo/baz/qux/
foo/baz/qux/hisfile.txt
foo/bar/
foo/bar/myfile.txt
foo/bar/yourfile.txt

With tree:

$ tree foo
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.

Vasu
  • 273

2 Answers2

21

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:

INPUT OPTIONS
    --fromfile
        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...

Septatrix
  • 309
8

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
foo
 ├─bar
 │  ├─myfile.txt
 │  └─yourfile.txt
 └─baz
    └─qux
       └─hisfile.txt

Also:

$ 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
grawity
  • 501,077