How to LS a Tree in Unix

How to LS a Tree in Unix thumbnail
Use Unix command line tools in combination by piping and redirection when a single utility does not produce the output required.

Shape the Unix LS command line output when browsing files and directories using command line switches that change the data presented on the screen to include the information you require. However, certain views, such as a directory tree view, require the help of other command line tools in addition to the LS command line switches. Use the Sed stream editor from the Unix command line to shape LS utility command line output so that directory tree structure is presented on the screen.

Things You'll Need

  • Path to the directory that is the top of the directory path for which you want to view the directory tree
Show More

Instructions

    • 1

      Open a command line terminal console.

    • 2

      Enter "cd /path_to_top_directory/" on the command line, and press the "Enter" key. Type "pwd" at the command prompt, and tap the "Enter" key. View the command line output, and confirm that the directory name displayed is the name of the directory at the top of the directory tree you wish to view.

    • 3

      Type "ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'" at the command prompt, and press the "Enter" key. The directory tree will display in the command line output.

Related Searches:

References

  • Photo Credit Comstock Images/Comstock/Getty Images

Comments

Related Ads

Featured