【Linux】Linux-treeコマンドを一歩一歩学ぶ(23)


00.目次
文書ディレクトリ
  • 00. ディレクトリ
  • 01. コマンド概要
  • 02. コマンドフォーマット
  • 03. 共通オプション
  • 04. 参考例
  • 05. 付録
  • 01.コマンドの概要
    treeコマンドは、ディレクトリの内容をツリーグラフでリストします.
    02.コマンドフォーマット
    tree[オプション][パラメータ]
    03.一般的なオプション
    -a          。
    -A   ASNI            ASCII    。
    -C             ,        。
    -d           。
    -D             。
    -f           ,           。
    -F      ,  ,Socket,    ,      ,    "*","/","=","@","|" 。
    -g               ,        ,        。
    -i               。
    -I                  。
    -l              ,               。
    -L     
    -n              。
    -N            ,      。
    -p       。
    -P                  。
    -q  "?"       ,         。
    -s          。
    -t              。
    -u              ,        ,        。
    -x               ,            ,            ,                。
    

    04.参考例
    4.1 treeコマンドのインストール、Centos 7.5を例に
    [deng@localhost test]$ yun install tree 
    

    4.2ツリー図でディレクトリの内容をリストする
    [deng@localhost test]$ mkdir -p a/b/c/d
    [deng@localhost test]$ tree a
    a
    └── b
        └── c
            └── d
    
    3 directories, 0 files
    [deng@localhost test]$ 
    

    4.3ディレクトリの内容を表示する場合、レベルを指定するtree -L nコマンドを使用して、nは数値で、現在のn番目のレベルのディレクトリとファイルを表示します.
    //            
    [deng@localhost home]$ tree -L 1 /home
    /home
    ├── deng
    └── oracle
    
    2 directories, 0 files
    [deng@localhost home]$ 
    
    //             
    [deng@localhost home]$ tree -L 2 /home
    /home
    ├── deng
    │   ├── bak
    │   ├── bj34
    │   ├── instantclient_11_2
    │   ├── oracle_client_11gR2.tar.gz
    │   ├── oradiag_deng
    │   ├── projects
    │   ├── scott_data.sql
    │   ├── share
    │   ├── sz12
    │   ├── test
    │   ├── test.c
    │   ├── test.cpp
    │   ├── \345\205\254\345\205\261
    │   ├── \346\250\241\346\235\277
    │   ├── \350\247\206\351\242\221
    │   ├── \345\233\276\347\211\207
    │   ├── \346\226\207\346\241\243
    │   ├── \344\270\213\350\275\275
    │   ├── \351\237\263\344\271\220
    │   └── \346\241\214\351\235\242
    └── oracle [error opening dir]
    
    18 directories, 4 files
    [deng@localhost home]$ 
    

    4.4各ファイルまたはディレクトリの前に、完全な相対パス名を表示します.
    [deng@localhost test]$ tree -f 
    .
    └── ./a
        └── ./a/b
            └── ./a/b/c
                └── ./a/b/c/d
    
    4 directories, 0 files
    [deng@localhost test]$ 
    

    4.5コンテンツではなくディレクトリ名が表示されます.
    [deng@localhost test]$ tree -d /etc/systemd/
    /etc/systemd/
    ├── system
    │   ├── basic.target.wants
    │   ├── bluetooth.target.wants
    │   ├── default.target.wants
    │   ├── dev-virtio\\x2dports-org.qemu.guest_agent.0.device.wants
    │   ├── getty.target.wants
    │   ├── graphical.target.wants
    │   ├── local-fs.target.wants
    │   ├── multi-user.target.wants
    │   ├── network-online.target.wants
    │   ├── printer.target.wants
    │   ├── remote-fs.target.wants
    │   ├── sockets.target.wants
    │   ├── sysinit.target.wants
    │   ├── system-update.target.wants
    │   ├── timers.target.wants
    │   └── vmtoolsd.service.requires
    └── user
    
    18 directories
    [deng@localhost test]$
    

    4.6ファイルと目次リストに色を加え、さまざまなタイプを区別しやすい.
    [deng@localhost ~]$ tree -C /home
    

    4.7ファイルまたはディレクトリのサイズをリストします.
    [deng@localhost test]$ tree -s a/
    a/
    └── [         15]  b
        └── [         15]  c
            └── [          6]  d
    
    3 directories, 0 files
    [deng@localhost test]$
    

    05.付録
    参考:【Linux】一歩一歩Linuxシリーズチュートリアルのまとめ