[COMMAND LINE] Display structure of directory hierarchy

Let's say you're working on the terminal and want to display current's directory hierarchy in a tree structure, like this:

$ tree.sh .kde/share/apps/krita/

/home/wilson/.kde/share/apps/krita
   .
   |-paintoppresets
   |-templates
   |---CMYK
   |---Ink
   |---WS
   |-workspaces

I found the command below on the web and its author even provided it as a shell script to use it easily.

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'

Install system wide

Open a terminal window and run:

dst="/usr/local/bin/tree.sh" && sudo wget http://goo.gl/z8exN -O $dst && sudo chmod +x $dst

Install for current user

This will install the script for your user only and assumes you have a bin directory on your home directory and it has been added to $PATH. Open a terminal window and run:

dst="$HOME/bin/tree.sh" && wget http://goo.gl/z8exN -O $dst && chmod +x $dst

References

Unix Tree / Linux Tree - Display Structure of Directory Hierarchy

Comments

  1. Why not just using the `tree` command? It does the same and has plenty of more options.

    ReplyDelete
  2. Up until now the script has all the functionality I need. Besides tree is not pre-installed and since I have a place for scripts outside the operating system partition, it'll be available if I choose to format.

    But still, tree is a option to take in consideration. Thank you.

    ReplyDelete
  3. "sudo wget http:// [...]" is an extremely bad idea. You don't just download something from obscured URLs as root, make it executeable and put it into /usr/local/bin/. It's a recipe for disaster. This kind of carelessness will compromize your system sooner or later. Users who are inclined to do this shouldn't have sudo access at all.

    ReplyDelete
    Replies
    1. Thank you for your concern, but the script provided here just runs the command quote on the main text of the article. And anyone who distrust this can check the contents of the file manually.

      Delete

Post a Comment

Popular posts from this blog

[HOW TO] Create QR Codes in Xubuntu 12.04

[FIX] VLC is unable to open the MRL (smb://)

Add items to Xfce Applications Menu