How do I limit the number of levels that the tree command goes through in Windows? I need to output the results to a text file for work, but because by default the tree command lists every single directory under the one you ran the command in, the output I'm getting is over 44,000 lines long, which isn't helpful at all for my work. How do I restrict it to listing just the first couple levels?
To move down another level, we type cd on the command line followed by the name of that directory. This allows us to move two directory levels with one command.
TREE (Display Directory) Purpose: Displays directory paths and (optionally) files in each subdirectory. When you use the TREE command each directory name is displayed along with the names of any subdirectories within it.
The tree is a tiny, cross-platform command-line program used to recursively list or display the content of a directory in a tree-like format. It outputs the directory paths and files in each sub-directory and a summary of a total number of sub-directories and files.
tree is a recursive directory displaying command that helps to see the in depth indented listing of directories and files.
Since I didn't found complete answer here. Here it is:
Windows CMD doesn't support -L
depth levels.
../../cygdrive/c/myFolder
.tree -L 3 >result.txt
.Actually, the tree
command in DOS and Windows does not have the option for specifying the directory level that the command goes through. You can refer to the documentation of tree on Microsoft Docs.
But you can use Git Bash instead. This tool is provided when you install Git for Windows. So in this way, you can use the command that @Zhengquan Feng mentioned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With