如何在 Bash 中显示事物树?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2444402/
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
How do I display a tree of things in Bash?
提问by pedro
How do I make a tree of all things with bash? What is the command?
我如何用 bash 制作所有事物的树?命令是什么?
回答by ghostdog74
tree /
or
或者
find /
Update: @OP, since you have so much trouble with it, how about this alternative. On ubuntu 9.10, you should have bash 4.0 ? so try this
更新:@OP,既然你遇到了这么多麻烦,那么这个替代方案怎么样。在 ubuntu 9.10 上,你应该有 bash 4.0 吗?所以试试这个
#!/bin/bash
shopt -s globstar
for rdir in /*/
do
for file in $rdir/**
do
echo "$file"
done
done
回答by Sola Zhou
$ find . -print | sed -e 's;/*/;|;g;s;|; |;g'
Add alias to ~/.bash_profile
将别名添加到 ~/.bash_profile
alias tree="find . -print | sed -e 's;/*/;|;g;s;|; |;g'"
回答by meatspace
you should probably alias this :)
你可能应该给这个别名:)
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
(Warning: huge output)
(警告:巨大的输出)
回答by Ben S
tree -R /
tree -R /
and then cry because it's enormous.
然后哭,因为它是巨大的。
On a related note, to stop the command, press CTRL+C
在相关说明中,要停止命令,请按CTRL+C
回答by swapnil mandavkar
Assuming you want to find something from tree, do
假设你想从树中找到一些东西,做
tree / > tree.txt
Then Ctrl + F it.
然后Ctrl+F吧。

