Wednesday, December 3, 2014

List files as a tree in Linux

Usually we have the directory listing as follows;

ls -l

Can we print the linux directory in a tree format? Yes we have several options, of which two is shown here.

Option 1

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

Option 2

Install the tree package (Steve Baker, Francesc Rocher) then execute it.

This command can specify depth of folders.
tree -L 2

No comments: