A simple command-line utility written in Go to display the directory structure in a tree-like format.
- Display files and directories in a structured, easy-to-read tree format.
- Optionally display hidden files and directories using the
-a
flag. - Exclude specific files or directories by name using the
-exclude
flag.
- Install Go (if not already installed).
- Clone this repository or copy the
tree.go
file.git clone https://github.com/vovakirdan/tree-view.git cd tree-view
- Build the utility:
go build tree.go
If you want to use it from anywhere in your linux system!
- Compile. Note that you can specify output file name.
- Copy (or move) binary to dir that included in PATH. As usual, it is a
/usr/local/bin
sudo cp tree /usr/local/bin/tree
You can use also:
sudo mv tree /usr/local/bin/
But sometimes somethings goes wrong and you have no such dir. Then, of course, you can create it:
sudo mkdir /usr/local/bin
An then, if you don't have this path in your $PATH
go:
- Open configuration file for your sh. For mac os it is zsh (
~/.zshrc
) by default, for bash it is bash profile (~/.bash_profile
)
vim ~/.zshrc
- Add
export PATH=$PATH:/usr/local/bin
to the file if don't even exists - Save and run
source ~/.zshrc
Then you can just move it to the dir.
- Move binary file to the homebrew path:
mkdir -p /usr/local/Cellar/tree/1.0/bin
mv tree /usr/local/Cellar/tree/1.0/bin/
- Create symbol link to utility:
ln -s /usr/local/Cellar/tree/1.0/bin/tree /usr/local/bin/tree
Check access via tree --help
. If everything is ok, you will see the help.
Run the utility from the command line:
./tree [options] <directory>
-a
Show hidden files and directories (those starting with a dot.
).-exclude=<names>
Exclude files and directories by name. Pass a comma-separated list.-emoji
Shows emoji near the file or path.
-
Display the current directory:
./tree .
-
Show hidden files and directories:
./tree -a .
-
Exclude specific directories (e.g.,
node_modules
andbuild
):./tree -exclude=node_modules,build .
-
Combine options: Show hidden files and exclude specific directories:
./tree -a -exclude=.git,node_modules .
Given a directory structure:
GoCall/
├── go.mod
├── main.go
├── server/
│ └── main.go
├── static/
│ ├── app.js
│ └── index.html
└── .git/
├── HEAD
└── config
Without hidden files:
./tree GoCall
Output:
GoCall/
├── go.mod
├── main.go
├── server/
│ └── main.go
└── static/
├── app.js
└── index.html
With hidden files:
./tree -a GoCall
Output:
GoCall/
├── .git/
│ ├── HEAD
│ └── config
├── go.mod
├── main.go
├── server/
│ └── main.go
└── static/
├── app.js
└── index.html
./tree -emoji
Output
📂 gocall/
├── 📜 GoCall
├── 📂 client/
│ ├── 💻 main.go
│ └── 💻 webrtc.go
├── 📜 go.mod
├── 📜 go.sum
├── 💻 main.go
├── 📂 server/
│ ├── 💻 main.go
│ ├── 💻 signaling.go
│ └── 💻 webrtc.go
└── 📂 static/
├── 💻 app.js
└── 📜 index.html
- Hidden files and directories (starting with
.
) are ignored by default. - The program works recursively and handles any depth of directories.
This project is licensed under the MIT License.