Linux命令以树的形式打印目录结构 [英] Linux command to print directory structure in the form of a tree

查看:259
本文介绍了Linux命令以树的形式打印目录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有任何linux命令,我可以调用从一个Bash脚本,将以树的形式打印目录结构,例如

  folder1 
a.txt
b.txt
folder2
folder3


解决方案

这是您寻找,应该在大多数发行版中(也许作为可选的安装)?

 〜> tree -d / proc / self / 
/ proc / self /
| - attr
| - cwd - > / proc
| - fd
| ` - 3 - > / proc / 15589 / fd
| - fdinfo
| - net
| | - dev_snmp6
| | - netfilter
| | - rpc
| | | - auth.rpcsec.context
| | | - auth.rpcsec.init
| | | - auth.unix.gid
| | | - auth.unix.ip
| | | - nfs4.idtoname
| | | - nfs4.nametoid
| | | - nfsd.export
| | ` - nfsd.fh
| `-stat
| - root - > /
` - task
` - 15589
| - attr
| - cwd - > / proc
| - fd
| ` - 3 - > / proc / 15589 / task / 15589 / fd
| - fdinfo
` - root - > /

27个目录

取自维护者网页。 >

您可以添加选项 -L#其中



删除 -d 以显示文件。


Is there any linux command that I can call from a Bash script that will print the directory structure in the form of a tree, e.g.,

folder1
   a.txt
   b.txt
folder2
   folder3

解决方案

is this what your looking for tree, should be in most distributions (maybe as an optional install)?

~> tree -d /proc/self/
/proc/self/
|-- attr
|-- cwd -> /proc
|-- fd
|   `-- 3 -> /proc/15589/fd
|-- fdinfo
|-- net
|   |-- dev_snmp6
|   |-- netfilter
|   |-- rpc
|   |   |-- auth.rpcsec.context
|   |   |-- auth.rpcsec.init
|   |   |-- auth.unix.gid
|   |   |-- auth.unix.ip
|   |   |-- nfs4.idtoname
|   |   |-- nfs4.nametoid
|   |   |-- nfsd.export
|   |   `-- nfsd.fh
|   `-- stat
|-- root -> /
`-- task
    `-- 15589
        |-- attr
        |-- cwd -> /proc
        |-- fd
        | `-- 3 -> /proc/15589/task/15589/fd
        |-- fdinfo
        `-- root -> /

27 directories

sample taken from maintainers web page.

You can add the option -L # where # is replaced by a number, to specify the max recursivity level.

Remove -d to display also files.

这篇关于Linux命令以树的形式打印目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆