linux目录操作命令 tree

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux目录操作命令 tree相关的知识,希望对你有一定的参考价值。

linux目录操作命令 tree

tree 命令

ls命令以目录树的方式来显示目录的内容。

语法

tree(选项)(参数)

选项

  • -a:显示所有文件和目录;
  • -A:使用ASNI绘图字符显示树状图而非以ASCII字符组合;
  • -C:在文件和目录清单加上色彩,便于区分各种类型;
  • -d:先是目录名称而非内容;
  • -D:列出文件或目录的更改时间;
  • -f:在每个文件或目录之前,显示完整的相对路径名称;
  • -F:在执行文件,目录,Socket,符号连接,管道名称名称,各自加上"*","/","@","|"号
  • -g:列出文件或目录的所属群组名称,没有对应的名称时,则显示群组识别码;
  • -l:如遇到性质为符号连接的目录,直接列出该连接所指向的原始目录;
  • -n:不在文件和目录清单加上色彩;
  • -N:直接列出文件和目录名称,包括控制字符;
  • -p:列出权限标示;
  • -P:<范本样式> 只显示符合范本样式的文件和目录名称;
  • -q:用“?”号取代控制字符,列出文件和目录名称;
  • -s:列出文件和目录大小; -t:用文件和目录的更改时间排序;
  • -u:列出文件或目录的拥有者名称,没有对应的名称时,则显示用户识别码;
  • -x:将范围局限在现行的文件系统中,若指定目录下的某些子目录,其存放于另一个文件系统上,则将该目录予以排除在寻找范围外。
  • -L: 后接数字,数字1指下一层目录。

参数

可以指定的文件或者目录,如果不加则列出文件或者目录

实例

  1. 显示所有文件和目录
[[email protected] tmp]# tree -a mylinux/ |head -9 
mylinux/
|-- etc
|   |-- dbus-1
|   |   `-- system.d
|   |       `-- cups.conf
|   |-- gshadow
|   |-- ld.so.conf.d
|   |   `-- kernel-2.6.32-358.el6.x86_64.conf
|   |-- pam.d
  1. 使用ASNI绘图字符显示树状图而非以ASCII字符组合
[[email protected] tmp]# tree -A mylinux/ |head -9
mylinux/
+-- etc
|   +-- dbus-1
|   |   +-- system.d
|   |       +-- cups.conf
|   +-- gshadow
|   +-- ld.so.conf.d
|   |   +-- kernel-2.6.32-358.el6.x86_64.conf
|   +-- pam.d
  1. 在文件和目录清单加上色彩,便于区分各种类型

技术分享

enter description here

4. 列出文件或目录的更改时间;

[[email protected] tmp]# tree -D mylinux/ |head -9 
mylinux/
|-- [May 20 14:21]  etc
|   |-- [May 20 14:21]  dbus-1
|   |   `-- [May 20 14:21]  system.d
|   |       `-- [May 20 14:21]  cups.conf
|   |-- [May 20 14:21]  gshadow
|   |-- [May 20 14:21]  ld.so.conf.d
|   |   `-- [May 20 14:21]  kernel-2.6.32-358.el6.x86_64.conf
|   |-- [May 20 14:21]  pam.d
  1. 在每个文件或目录之前,显示完整的相对路径名称;:
[[email protected] tmp]# tree -f mylinux/ |head -9 
mylinux
|-- mylinux/etc
|   |-- mylinux/etc/dbus-1
|   |   `-- mylinux/etc/dbus-1/system.d
|   |       `-- mylinux/etc/dbus-1/system.d/cups.conf
|   |-- mylinux/etc/gshadow
|   |-- mylinux/etc/ld.so.conf.d
|   |   `-- mylinux/etc/ld.so.conf.d/kernel-2.6.32-358.el6.x86_64.conf
|   |-- mylinux/etc/pam.d

6.在执行文件,目录,Socket,符号连接,管道名称名称,各自加上"*","/","@","|"号:

[[email protected] tmp]# tree -F mylinux/ |head -9 
mylinux/
|-- etc/
|   |-- dbus-1/
|   |   `-- system.d/
|   |       `-- cups.conf
|   |-- gshadow
|   |-- ld.so.conf.d/
|   |   `-- kernel-2.6.32-358.el6.x86_64.conf
|   |-- pam.d/
  1. 列出文件或目录的所属群组名称,没有对应的名称时,则显示群组识别码
[[email protected] tmp]# tree -g mylinux/ |head -9
mylinux/
|-- [root    ]  etc
|   |-- [root    ]  dbus-1
|   |   `-- [root    ]  system.d
|   |       `-- [root    ]  cups.conf
|   |-- [root    ]  gshadow
|   |-- [root    ]  ld.so.conf.d
|   |   `-- [root    ]  kernel-2.6.32-358.el6.x86_64.conf
|   |-- [root    ]  pam.d
  1. 如遇到性质为符号连接的目录,直接列出该连接所指向的原始目录;
[[email protected] mnt]# tree -l /mnt
/mnt
|-- 2
|-- file1
|-- file22222
|-- history
`-- passwd -> /tmp/mylinux/etc/gshadow

0 directories, 5 files

9 . 列出权限标示:

[[email protected] mnt]# tree -p /etc |head -9 
/etc
|-- [drwxr-xr-x]  ConsoleKit
|   |-- [drwxr-xr-x]  run-seat.d
|   |-- [drwxr-xr-x]  run-session.d
|   `-- [drwxr-xr-x]  seats.d
|       `-- [-rw-r--r--]  00-primary.seat
|-- [-rw-r--r--]  DIR_COLORS
|-- [-rw-r--r--]  DIR_COLORS.256color
|-- [-rw-r--r--]  DIR_COLORS.lightbgcolor
  1. 列出文件或目录的拥有者名称,没有对应的名称时,则显示用户识别码:
[[email protected] mnt]# tree -u /etc |head -9 
/etc
|-- [root    ]  ConsoleKit
|   |-- [root    ]  run-seat.d
|   |-- [root    ]  run-session.d
|   `-- [root    ]  seats.d
|       `-- [root    ]  00-primary.seat
|-- [root    ]  DIR_COLORS
|-- [root    ]  DIR_COLORS.256color
|-- [root    ]  DIR_COLORS.lightbgcolor
[[email protected] mnt]# 


以上是关于linux目录操作命令 tree的主要内容,如果未能解决你的问题,请参考以下文章

linux文件目录操作常用命令

Linux核心系统命令

linux初级学习笔记二:linux操作系统及常用命令_mkdir_rm_touch_stat_tree,文件夹操作,文件目录的用处,文件夹展开!(视频序号:02_3)

Linux 常用操作命令

Linux 常用操作命令

Python Web:Linux查看切换目录命令