yangshun/tree-node-cli được TopGit xếp vào nhóm công cụ cho lập trình viên, với 292 sao trên GitHub, viết chủ yếu bằng TypeScript. List directory contents in a tree-like format, similar to the Linux tree command
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Lists the contents of directories in a tree-like format, similar to the Linux tree command. Both CLI and Node.js APIs are provided.
tree is a command that produces a nicely-formatted indented output of directories and files. When a directory argument is given, tree lists all the files and/or directories found in the given directory.
Note: Symlinks are not followed. Directories that cannot be opened (e.g. due to permission errors) are listed with [error opening dir] instead of crashing, matching Linux tree behavior.
Quickstart
Instantly execute the command in your current directory via npx / pnpx / bunx / yarn dlx:
npx tree-node-cli
Installation
npm install tree-node-cli
# or globally
npm install -g tree-node-cli
[!NOTE]
gitignore is respected by default so node_modules and other common files/directories are excluded automatically. Use --no-gitignore to show them.
CLI
tree [options] [path/to/dir]
[!IMPORTANT]
Use the command treee on Windows and Linux to avoid conflicts with built-in tree command.
The following options are available:
$ tree --help
Usage:
$ tree <command> [options]
Options:
Listing options:
-a, --all-files All files, including hidden files, are printed.
-d, --dirs-only List directories only.
-f, --full-path Print the full path prefix for each file.
-L, --max-depth <n> Max display depth of the directory tree.
-I, --exclude <patterns> Exclude files that match the pattern. | separates
alternate patterns. Wrap your entire pattern in double
quotes. E.g. "node_modules|coverage".
--gitignore Respect .gitignore files (enabled by default).
Use --no-gitignore to disable.
--prune Remove empty directories from output.
File options:
-Q, --quote Quote filenames in double quotes.
-p, --permissions Show file type and permissions.
-s, --sizes Print the size of each file in bytes along with the name.
-h, --human-readable Print file sizes in human-readable format (powers
of 1024). Implies -s.
--si Print file sizes using SI units (powers of 1000).
Implies -s.
--du For each directory report its size as the accumulation
of sizes of all its files and sub-directories. Implies -s.
-D, --date Show last modification time for each entry.
-F, --trailing-slash Append a '/' for directories.
Sorting options:
-v, --version-sort Sort the output by version (natural sort of numbers
within text).
-t, --sort-mtime Sort the output by last modification time.
-c, --sort-ctime Sort the output by last status change time.
-U, --unsorted Do not sort. List files in directory order.
-r, --reverse Sort the output in reverse alphabetic order.
--dirs-first List directories before files.
--files-first List files before directories.
--sort <type> Sort the output by type: name, version, mtime,
ctime, size.
Graphics options:
-i, --no-indent Print entries without tree indentation lines.
-S, --line-ascii Turn on ASCII line graphics.
Output options:
-J, --json Output the tree as a JSON structure.
Misc options:
--help Display this message
--version Display version number
[!TIP]
To exclude the contents of a directory while still printing the directory itself, use a trailing slash with the -I option (e.g., -I "directory/").
For the Node.js API, provide a regex matching the directory contents (e.g., /directory\//). Directories listed in .gitignore (e.g. node_modules) are already excluded by default, use --no-gitignore in combination with -I "directory/" if you want them to show up.
Node.js API
tree(path, options?)
Returns the tree as a formatted string.
import { tree } from 'tree-node-cli';
const string = tree('path/to/dir', {
allFiles: true,
exclude: [/vendor/, /lcov/],
maxDepth: 4,
});
console.log(string);
treeJson(path, options?)
Returns the tree as a structured TreeJsonEntry object (or null if the path is excluded).
// Discriminated union — `contents` only exists on directories
type TreeJsonEntry =
| {
type: 'directory';
name: string;
contents: TreeJsonEntry[];
size?: number;
mode?: string;
time?: string;
}
| { type: 'file'; name: string; size?: number; mode?: string; time?: string };
// size: present when `sizes: true`
// mode: present when `permissions: true`
// time: present when `date: true`
// error: present when the directory could not be opened (e.g. permission denied)
options is a configuration object with the following fields:
Field
Default
Type
Description
allFiles
false
boolean
All files, including hidden files, are printed.
dirsOnly
false
boolean
List directories only.
fullPath
false
boolean
Print the full path prefix for each file.
maxDepth
Number.POSITIVE_INFINITY
number
Max display depth of the directory tree.
exclude
[]
RegExp[]
An array of regex to test each filename against. Matching files will be excluded and matching directories will not be traversed into. To exclude a directory's contents while still showing the directory itself, use a regex that matches the path with a trailing slash (e.g., /vendor\//).
gitignore
true
boolean
Respect .gitignore files when inside a git repository. Use --no-gitignore to disable.
prune
false
boolean
Remove empty directories from output.
quote
false
boolean
Quote filenames in double quotes.
permissions
false
boolean
Show file type and permissions (e.g. [drwxr-xr-x]).
sizes
false
boolean
Print the size of each file in bytes along with the name.
humanReadable
false
boolean
Print file sizes in human-readable format (powers of 1024). Implies sizes.
si
false
boolean
Print file sizes using SI units (powers of 1000). Implies sizes.
du
false
boolean
For each directory, report its size as the accumulation of sizes of all its files and sub-directories. Implies sizes.
date
false
boolean
Show last modification time for each entry.
trailingSlash
false
boolean
Append a / for directories.
sortBy
'name'
string
Sort the output. Options: 'name', 'version', 'mtime', 'ctime', 'size'.
Vì sao yangshun/tree-node-cli được xếp vào nhóm Developer Tools?
TopGit xếp yangshun/tree-node-cli vào nhóm Developer Tools dựa trên GitHub topics và mô tả của repo (gắn thẻ: "cli", "directory", "file"). Việc phân loại dựa trên metadata thật của repo, không phải đoán theo cảm tính biên tập.
yangshun/tree-node-cli có bao nhiêu sao?
yangshun/tree-node-cli có 292 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/yangshun/tree-node-cli. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
yangshun/tree-node-cli có những chủ đề gì?
GitHub topics của yangshun/tree-node-cli: "cli", "directory", "file", "hacktoberfest", "linux", "node", "tree". TopGit xếp repo vào nhóm Developer Tools.
yangshun/tree-node-cli còn đang phát triển không?
Commit gần nhất trên yangshun/tree-node-cli là 7 tháng trước (theo timestamp GitHub). Repo có 31 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
yangshun/tree-node-cli là gì?
yangshun/tree-node-cli (yangshun/tree-node-cli) là dự án TypeScript trên GitHub. Theo mô tả gốc: List directory contents in a tree-like format, similar to the Linux tree command
yangshun/tree-node-cli so với các dự án Developer Tools khác thế nào?
yangshun/tree-node-cli được TopGit xếp vào nhóm Developer Tools, với 292 sao GitHub và viết bằng TypeScript. Xem trang chủ đề Developer Tools trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
yangshun/tree-node-cli viết bằng ngôn ngữ gì?
yangshun/tree-node-cli chủ yếu viết bằng TypeScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
tree-node-cli có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về tree-node-cli.