Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMD tree command limit number of levels

Tags:

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?

like image 576
iqover9000 Avatar asked Aug 10 '15 19:08

iqover9000


People also ask

How do you go down a level in CMD?

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.

What does the tree command do in CMD?

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.

What is the tree command in Linux?

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.

What is the tree command on Mac?

tree is a recursive directory displaying command that helps to see the in depth indented listing of directories and files.


2 Answers

Since I didn't found complete answer here. Here it is:

Windows CMD doesn't support -L depth levels.

  1. Install CygWin https://www.cygwin.com.
  2. In Cygwin make sure you pick Utilities / Tree package installed.
  3. Open CygWin and navigate to your folder, like cd ../../cygdrive/c/myFolder.
  4. List tree structure and save as result.txt tree -L 3 >result.txt.
like image 194
Dariusz Sikorski Avatar answered Sep 22 '22 19:09

Dariusz Sikorski


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.

like image 38
Jesse Chen Avatar answered Sep 23 '22 19:09

Jesse Chen