osx bash 上的树命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8304172/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
tree command on osx bash
提问by JZ.
I'm following a screen caston a ruby gem called pry. At 8:10, the .tree command is used, which I believe is a Unix command.
我正在跟踪一个名为pry的红宝石宝石的屏幕投射。8点10分,使用了.tree命令,我相信这是一个Unix命令。
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 引用了一个 shell 命令:
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 =
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:
从 bash 的上下文中,我尝试使用命令树但没有运气:
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?
这看起来非常有用,我怎样才能得到这个命令?
回答by Dave Newton
Using homebrew:
使用自制软件:
brew install tree
brew install tree
Using macports:
使用macports:
sudo port install tree
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>
<rant>所有系统都应该带有tree; 我经常使用它。我们可以将目录结构作为文本发布,而不是图片。</rant>
回答by Grokify
For a simple approach you can also add the following alias to your ~/.bashrcor ~/.zshrcfile:
对于简单的方法,您还可以将以下别名添加到您的~/.bashrc或~/.zshrc文件:
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:
在这里找到了这个解决方案:

