• Linux命令--tree--使用/详解/实例


    原文网址: 见:Linux命令--tree--使用/详解/实例_IT利刃出鞘的博客-CSDN博客

    简介

            本文用示例介绍Linux的tree命令的用法。

            tree命令可以以树状结构查看目录结构。

    选项

    列表选项

    • -a            # 显示所有文件和目录。
    • -d            # 显示目录名称而非文件。
    • -l            # 如遇到性质为符号连接的目录,直接列出该连接所指向的原始目录。
    • -f            # 在每个文件或目录之前,显示完整的相对路径名称。
    • -x            # 将范围局限在现行的文件系统中。若指定目录下的某些子目录,其存放于另一个文件系统上,则将该目录予以排除在寻找范围外。
    • -L level      # 限制目录显示层级。
    • -R            # Rerun tree when max dir level reached.
    • -P pattern    # <范本样式> 只显示符合范本样式的文件和目录名称。
    • -I pattern    # Do not list files that match the given pattern.
    • --ignore-case # Ignore case when pattern matching.
    • --matchdirs   # Include directory names in -P pattern matching.
    • --noreport    # Turn off file/directory count at end of tree listing.
    • --charset X   # Use charset X for terminal/HTML and indentation line output.
    • --filelimit # # Do not descend dirs with more than # files in them.
    • --timefmt <f> # Print and format time according to the format <f>.
    • -o filename   # Output to file instead of stdout.

    文件选项

    • -q            # 用“?”号取代控制字符,列出文件和目录名称。
    • -N            # 直接列出文件和目录名称,包括控制字符。
    • -p            # 列出权限标示。
    • -u            # 列出文件或目录的拥有者名称,没有对应的名称时,则显示用户识别码。
    • -g            # 列出文件或目录的所属群组名称,没有对应的名称时,则显示群组识别码。
    • -s            # 列出文件和目录大小。
    • -D            # 列出文件或目录的更改时间。
    • -F            # 在执行文件,目录,Socket,符号连接,管道名称名称,各自加上"*","/","@","|"号。
    • -Q            # Quote filenames with double quotes.
    • -h            # Print the size in a more human readable way.
    • --si          # Like -h, but use in SI units (powers of 1000).
    • --inodes      # Print inode number of each file.
    • --device      # Print device ID number to which each file belongs.

    排序选项

    • -t            # 用文件和目录的更改时间排序。
    • -v            # Sort files alphanumerically by version.
    • -c            # Sort files by last status change time.
    • -U            # Leave files unsorted.
    • -r            # Reverse the order of the sort.
    • --dirsfirst   # List directories before files (-U disables).
    • --sort X      # Select sort: name,version,size,mtime,ctime.

    图形选项

    • -i            # 不以树状列出文件和目录名称。
    • -A            # 使用ASNI绘图字符显示树状图而非以ASCII字符组合。
    • -C            # 在文件和目录清单加上色彩,便于区分各种类型。
    • -S            # Print with CP437 (console) graphics indentation lines.
    • -n            # Turn colorization off always (-C overrides).

    XML / HTML / JSON选项

    • -X            # Prints out an XML representation of the tree.
    • -J            # Prints out an JSON representation of the tree.
    • -H baseHREF   # Prints out HTML format with baseHREF as top directory.
    • -T string     # Replace the default HTML title and H1 header with string.
    • --nolinks     # Turn off hyperlinks in HTML output.

    杂项选项

    • --version     # 输入版本信息。
    • --help        # 打印使用帮助信息。
    • --            # Options processing terminator.

    示例

    完整文件结构如下(tree -a):

    1. .
    2. |-- .gitignore
    3. |-- .idea
    4. | |-- .gitignore
    5. | |-- compiler.xml
    6. | |-- encodings.xml
    7. | |-- jarRepositories.xml
    8. | |-- libraries
    9. | | |-- Maven__ch_qos_logback_logback_classic_1_2_7.xml
    10. | | |-- Maven__ch_qos_logback_logback_core_1_2_7.xml
    11. | | |-- ......
    12. | | `-- Maven__org_yaml_snakeyaml_1_27.xml
    13. | |-- misc.xml
    14. | |-- modules.xml
    15. | |-- vcs.xml
    16. | `-- workspace.xml
    17. |-- .mvn
    18. | `-- wrapper
    19. | |-- maven-wrapper.jar
    20. | `-- maven-wrapper.properties
    21. |-- HELP.md
    22. |-- demo_lock4j_SpringBoot.iml
    23. |-- mvnw
    24. |-- mvnw.cmd
    25. |-- pom.xml
    26. `-- src
    27. |-- main
    28. | |-- java
    29. | | `-- com
    30. | | `-- knife
    31. | | `-- demo
    32. | | `-- DemoLock4jSpringBootApplication.java
    33. | `-- resources
    34. | `-- application.yml
    35. `-- test
    36. `-- java
    37. `-- com
    38. `-- knife
    39. `-- demo

    tree不加参数

    命令:tree

    结果:

    可以发现,它没有显示出以点号开头的文件夹的内容。

    显示所有

    命令:tree -a

    结果:

    指定目录

    命令:tree 目录名

    结果:

    指定层数

    命令:tree -L 2

    结果:

    忽略文件夹+指定层数

    命令:tree -I 'pom.xml|.idea' -aL 2

    结果:

  • 相关阅读:
    JavaWep开始
    MySQL 核心模块揭秘 | 15 期 | 事务模块小结
    Blazor前后端框架Known-V1.2.10
    1. Gradle是什么,Gradle与Maven有什么不同
    http实现文件分片下载
    k8s-11 网络策略
    Java — 内部类
    el-table 指定层级展开
    MDT服务器的安装
    C/C++整数和与均值 2019年9月电子学会青少年软件编程(C/C++)等级考试一级真题答案解析
  • 原文地址:https://blog.csdn.net/feiying0canglang/article/details/125411638