Linux 基本工具(tree)
我们在查看系统所有进程的进程树可以使用 pstree
, 例如:
root@server:/etc/X11# pstree
systemd─┬─VBoxService─┬─{automount}
│ ├─{control}
│ ├─{cpuhotplug}
│ ├─{memballoon}
│ ├─{timesync}
│ ├─{vminfo}
│ └─{vmstats}
├─accounts-daemon─┬─{gdbus}
│ └─{gmain}
├─acpid
├─atd
├─cgmanager
├─cron
├─dbus-daemon
├─dhclient
├─dhcpd
├─dnsmasq───dnsmasq
├─3*[dynomite───2*[{dynomite}]]
├─epmd
├─in.tftpd
├─irqbalance
├─2*[iscsid]
......
而对于某个目录, 我们想知道目录树下的大致结构以及目录下的文件布局信息, 我们可以使用 tree
命令, tree
非系统核心包, 需要手动安装:
REHL/CentOS:
yum -y install tree
Debian/Ubuntu:
apt -y install tree
查看下 /etc/X11
目录布局信息:
root@server:/etc/X11# tree
.
├── rgb.txt
├── xinit
│ └── xinitrc.d
├── xkb
├── Xreset
├── Xreset.d
│ └── README
├── Xresources
│ └── x11-common
├── Xsession
├── Xsession.d
│ ├── 20x11-common_process-args
│ ├── 30x11-common_xresources
│ ├── 35x11-common_xhost-local
│ ├── 40x11-common_xsessionrc
│ ├── 50x11-common_determine-startup
│ ├── 60x11-common_localhost
│ ├── 60x11-common_xdg_path
│ ├── 60xdg-user-dirs-update
│ ├── 70gconfd_path-on-session
│ ├── 75dbus_dbus-launch
│ ├── 90qt-a11y
│ ├── 90x11-common_ssh-agent
│ ├── 95dbus_update-activation-env
│ └── 99x11-common_start
└── Xsession.options
6 directories, 20 files
这样就非常清晰的知道整个目录下的文件/目录信息了,便于快速了解一些大型项目的目录层次结构,或者用于根据文件大小组织目录下的文件分布
tree
有些重要的选项,便于我们使用:
-f
展示完整路径-L level
tree命令展示的目录深度-P pattern
查询模式串匹配的文件的布局信息, 比如-P *html
-d
仅仅展示目录-r
相对默认顺序, 反序输出-t
按修改时间排序输出--dirsfirst
优先输出目录-F
展示文件类型定位符号, "/" 表示 "dir", "*" 表示可执行文件-p
展示权限和类型-h
展示文件大小信息