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
Try to download WSL in your Windows system.
In your command prompt:
bash
Then you can use Linux commands:
tree -L x(the layer)
Actually, tree
command in DOS does not have the level
option. You can refer the manual: tree in windows.
But, you can use the git bash
(this is a tool provided by git when you installed the git on windows) or babun
(it's a really good tool for windows user to use the *unix tools) so in this way, you can use the command that @Zhengquan Feng mentioned.
If you use WSL you can also export the result straight to the Windows clipboard
tree
installed: sudo apt install tree
tree -L 5 | clip.exe
(replace 5
with however many levels deep you want)That'll bypass saving it to a txt file and go straight to your clipboard for quick pasting into forums, etc.
You can try this project on Windows :
https://github.com/MrRaindrop/tree-cli
Usage:
use -l
levelNumber to specify the path level:
treee -l 2
Example 3 levels:
tree|findstr /v /r /c:"^........│" /c:"^│....... " /c:"^ ....... "
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
.