Linux tree command

G

Govinda Sakhare

Guest
i wanted tree view of folders so i used below listed command .Please someone explain me this command
ls -R $var | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//|--/g' -e 's/^/ /' -e 's/-/|/'
 

Attachments

  • Q3.txt
    507 bytes · Views: 911


Explaining this command means explaining regular expressions, something that people have literally written whole books about.

In a nutshell $var is a variable I'd assume is the root directory you're looking to get a tree mapping of. ls -R is listing every directory tree recursively, it then grabs all the lines that end in : aka all directory lines

The sed commands edit the streams to produce the file-tree look of the result. It replaces the first expression with the second, so:
sed 's/this/that/' will replace all occurences of 'this' with 'that'.

It is MUCH more complex than this. The details of sed could fill another book, volume two of the regular expressions anthology.

You can ultimately get all the same info just using ls -R $var | grep ":$", all the other commands just make it look prettier.

If you want to learn more about sed and regular expressions there is a lot of good info online. Here is a good tutorial: http://www.grymoire.com/Unix/index.html
 

Members online


Latest posts

Top