如何在 Bash 中显示事物树?

发布于 2024-08-24 17:54:00 字数 35 浏览 3 评论 0原文

如何用 bash 制作一棵包含所有事物的树?命令是什么?

How do I make a tree of all things with bash? What is the command?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

阪姬 2024-08-31 17:54:00
tree /

find / 

更新:@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
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

#!/bin/bash
shopt -s globstar
for rdir in /*/
do
    for file in $rdir/**
    do
      echo "$file"
    done
done
娇俏 2024-08-31 17:54:00

你可能应该给这个别名:)

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/ |/'

(警告:巨大的输出)

you should probably alias this :)

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

(Warning: huge output)

天生の放荡 2024-08-31 17:54:00

tree -R /

然后哭,因为它太大了。

在相关说明中,要停止该命令,请按 CTRL+C

tree -R /

and then cry because it's enormous.

On a related note, to stop the command, press CTRL+C

掐死时间 2024-08-31 17:54:00
$ find . -print | sed -e 's;/*/;|;g;s;|; |;g'

将别名添加到 ~/.bash_profile

alias tree="find . -print | sed -e 's;/*/;|;g;s;|; |;g'"
$ find . -print | sed -e 's;/*/;|;g;s;|; |;g'

Add alias to ~/.bash_profile

alias tree="find . -print | sed -e 's;/*/;|;g;s;|; |;g'"
诗化ㄋ丶相逢 2024-08-31 17:54:00

假设您想从树中查找某些内容,

    tree / > tree.txt

然后按 Ctrl + F 即可。

Assuming you want to find something from tree, do

    tree / > tree.txt

Then Ctrl + F it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文