preface

Sometimes when we need to show the structure of the project when we write the README, we can make good use of the Mac tool Tree to help us quickly generate.

1. Install tree

brew install tree
Copy the code

2. Parameter Description

Parameter -a# Show all files, including hidden files (with ". Click file at the beginning)
-d # display directory only
-f Display only the full path of each file
-i # Do not display branches, often used with the -f argument
-L # level Specifies the maximum number of levels to traverse a directory. Level is a positive integer greater than 0
-F # in the executable file, directory, Socket symbolic links, pipes, name, etc. At the end of the different types of files, each with "*", "/", "=", "@", "|" number, the -f option similar to the ls command
Copy the code

3. The demo directory

# Test the file hierarchy of the project├── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ─ ├. Uninhibited-garbage ─ TitleCell ├. Uninhibited-garbageCopy the code

4. Generate the specified file

Tree [-d] -l ${number} > ${filename [. Suffix]} tree [-d] -l ${number} > ${filename [. Suffix]}

  • tree -L 3 > test1.md

    └── ── exdirectoriesCopy the code
  • tree -d -L 3 > test2.md

    ├── ├─ ├─ exdirectories, 3 filesCopy the code

5. Directly invoke the tree without any parameters

tree The above demo results will be directly printed on the terminal
Copy the code

6. Display all contents in the directory in a tree structure (-a function)

. ├ ─ ─. DS_Store └ ─ ─ the SRC ├ ─ ─ the DS_Store └ ─ ─ components ├ ─ ─ the DS_Store └ ─ ─ common ├ ─ ─ the DS_Store ├ ─ ─ FootCell │ └ ─ ─ index. The vue ├─ Pagination │ ├─ Table │ ├─ Pagination │ ├─ Pagination │ ├─ indexCopy the code

7. List only the directory structure at the bottom of the directory (-l function)

  • Layer 1 tree-L 1

    . └ ─ ─ the SRCCopy the code
  • Layer-2 tree-L 2

    .├ ── SRC ├ ─Copy the code
  • Tree -L 3

    .├ ── ── garbageCopy the code

8. Show all directories (but no files)

  • There is no path tree-d

    Displays the directory of the current file

    KaKa:test hhdd$ tree -d
    # the results└─ SRC ├── Common ├─ Pagination ├─ Table ├─ exdirectoriesCopy the code
  • Tree -d ${path}

    Displays the directory of the file under the specified path

    KaKa-3:test hhdd$ tree -d /Users/hhdd/Desktop/test
    # output result
    /Users/hhdd/Desktop/test├── SRC ├── common ├── Pagination ├─ Table ├─ exdirectoriesCopy the code
  • With parameter tree – dL ${number} | | tree – d – L ${number} – d parameters only show directory, -l parameter display layers

    KaKa-3:test hhdd$ tree -dL 1
    # the results└─ SRC 1 directoryCopy the code

9. -fOptions and-iUse of options

Use the -f option to display the full path name, use the -I option to display the branch part, as shown in the following code:

  • -f Displays a complete path name

    KaKa-3:test hhdd$ tree -d -L 2 -f
    # the results.├ ──./ SRC/directoriesCopy the code
  • -I does not show the branch part

    KaKa-3:test hhdd$ tree -d -L 2 -f -i
    # output result
    .
    ./src
    ./src/components
    
    2 directories
    Copy the code

10. Run the tree commanddirectoryandfile(Commonly used)

If the -f parameter is used, a slash is added to the end of the directory to distinguish the directory

  • Tree -l ${number} -f [${path}]

  • A path

    KaKa-3:test hhdd$ tree -L 1 -F /Users
    
    # output result/ │ ├── │ ├── exdirectories, 0 filesCopy the code
  • No path parameter

    KaKa-3:test hhdd$ tree -L 1 -F
    
    # output result.├ ── SRC / 1 directory, 0 filesCopy the code
  • Minus F for comparison

    KaKa-3:test hhdd$ tree -L 1
    
    # output result└─ SRC 1 directory, 0 filesCopy the code