[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
Why not just using the `tree` command? It does the same and has plenty of more options.
ReplyDeleteUp 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.
ReplyDeleteBut still, tree is a option to take in consideration. Thank you.
"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.
ReplyDeleteThank 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