Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tree command on osx bash

I'm following a screen cast on a ruby gem called pry. At 8:10, the .tree command is used, which I believe is a Unix command.

It does not appear to be working on my system:

[24] pry(main)> .tree \Error: there was a problem executing system command: tree 

and I have traced the issue to here, in which pry references a shell command:

Pry::CommandSet.new do    command(/\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => ".<shell command>") do |cmd|     if cmd =~ /^cd\s+(.+)/i       dest = $1       begin         Dir.chdir File.expand_path(dest)       rescue Errno::ENOENT         output.puts "No such directory: #{dest}"       end      else       if !system(cmd)         output.puts "Error: there was a problem executing system command: #{cmd}"       end     end   end 

from the context of bash I tried using the command tree with no luck:

projects/sms(apps2)$ tree -bash: tree: command not found ~/projects/sms(apps2)$ .tree -bash: .tree: command not found 

This looks incredibly useful, how can I get this command?

like image 904
JZ. Avatar asked Nov 29 '11 00:11

JZ.


People also ask

Is there a tree command for Mac?

Installing 'tree' for the Mac Command Line Once installed from either, typing 'tree' will display the folder tree of any directory on the Mac. Note to avoid conflict, you won't want to use a tree alias in the first step and then also install the tree command.

What is tree command in Bash?

The “tree” command is a very extensively used Bash command in Linux. It is used to display the contents of any desired directory of your computer system in the form of a tree structure.


2 Answers

Using homebrew:

brew install tree

Using macports:

sudo port install tree

Using the source:

Follow these directions. (Caveat; you should use the flags/etc. that make sense.)

<rant>All systems should come with tree; I use it a lot. And we can post directory structures as text, not pics.</rant>

like image 93
Dave Newton Avatar answered Oct 05 '22 04:10

Dave Newton


For a simple approach you can also add the following alias to your ~/.bashrc or ~/.zshrc file:

alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'" 

This results in the following:

$ tree . |____.git | |____config | |____objects | | |____pack | | |____info | |____HEAD | |____info | | |____exclude | |____description | |____hooks | | |____commit-msg.sample | | |____pre-rebase.sample | | |____pre-commit.sample | | |____applypatch-msg.sample | | |____pre-receive.sample | | |____prepare-commit-msg.sample | | |____post-update.sample | | |____pre-applypatch.sample | | |____pre-push.sample | | |____update.sample | |____refs | | |____heads | | |____tags 

Found this solution here:

  • http://osxdaily.com/2016/09/09/view-folder-tree-terminal-mac-os-tree-equivalent/
like image 37
Grokify Avatar answered Oct 05 '22 04:10

Grokify