0

I am wondering if it's possible to output the contents of a tar.gz file using tree without having to extract the contents of the file to a temp directory then using tree with that directory.

I know we can see the contents of the file without extracting using

tar -tf file.tar.gz

And I have simply tried piping this to the tree command

tar -tf file.tar.gz | tree

But this just outputs the tree of the current directory, not the contents of the file.

A few questions,

  1. Is this even possible?
  2. If it is possible, are there any limitations? Depth, number of files, etc?
  3. Is there an alternative way to see a tree style output of the contents?
2

Custom tree script treeify.py created by Hakril would help to pretty print contents of tgz without extracting

[root@bastion ~]# wget https://bitbucket.org/Hakril/treeify/raw/8e732368f64d30ffc4033cbc890164fdf296d9f8/treeify.py
[root@bastion ~]# tar -tvf  neo4j-enterprise.tar.gz | python treeify.py 
.
├─ drwxrwxrwx root
│  ├─ root         0 2019-05-09 05:05 neo4j-enterprise
│  │  └─ local-package
│  │    └─ 
│  └─ root         0 2019-05-15 02:01 neo4j-enterprise
│    └─ 
└─ -rwxr-xr-x root
  ├─ root         0 2019-05-09 05:05 neo4j-enterprise
  │  ├─ local-package
  │  │  └─ .sentinel
  │  └─ .sentinel
  ├─ root     10156 2019-05-09 05:05 neo4j-enterprise
  │  └─ docker-entrypoint.sh
  └─ root      1560 2019-05-14 21:36 neo4j-enterprise
    └─ Dockerfile
[root@bastion ~]# 


Ref : https://superuser.com/questions/1086501/list-contents-of-tarball-in-tree-format

  • Thanks for the suggestion, but I am getting an error per the python code: – Schwagmister May 21 at 15:13
  • [05-21-2019__11:12:29] root@MININT-L62JL0A:/usr/local# ls | python treeify.py File "treeify.py", line 1 <!DOCTYPE html> ^ SyntaxError: invalid syntax – Schwagmister May 21 at 15:13
  • Error output says 'DOCTYPE html'. Can you double check the python script?. – Naveen May 21 at 15:21
  • Yeah, so the py file I downloaded from bitbucket for that developer is all HTML, there is no python code anywhere. Any ideas? Are you seeing the same thing if you download it? – Schwagmister May 21 at 15:27
  • 1
    Sweet, Yay!! my first answer in this site. – Naveen May 21 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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