Many friends may use a tree directory when writing documents or sorting out directory structures. Before, I had been thinking about how tired it would be if I wrote little by little and sorted out little by little. Now it seems that MY knowledge is so narrow.
A github directory structure with a few CSS tips written by myself that hasn’t been updated in a while
Just like the simple directory structure above, now just go to the directory and type: tree. And we’re done.
Yes, this time the main purpose is to record the tree command.
The installation
In Windows, do not know which version of the start, anyway I remember before using Win7 when there is a built-in tree command, but seems to be relatively simple function. On the Mac, install via BREW package management.
brew install tree
Copy the code
Well, the installation may be slow, mainly because of the network, which we all know. It is said that it is possible to change the brew resource path, but for those who do not often look for installation packages on this path, I can not consider it, anyway I feel tired.
use
After you install the Tree, you can look at the help.
tree --help
Copy the code
You get a bunch of parameters that you can use, and I think the ones that are useful are about this.
Traverse the display hierarchy
If the directory level is deep, but you do not want to display all, you can use the -L number to do this, for example: display the first directory structure.
tree -L 1
Copy the code
Show folder
tree -d
Copy the code
Output specified format
In normal cases, the output format from tree is the same as in the screenshot above, but we can specify some formats for the output, which can be seen from tree –help.
This can be handy when making a sitemap with static pages, or when you want to export a JSON format.
Like the path of the output is under the domain name http://lab.tianyizone.com/, so as long as the input:
tree -H http://lab.tianyizone.com/
Copy the code
You get:
Not only the path and everything, but also the style. Of course, these styles can be dealt with in the later stage. If you feel uncomfortable with the tree characters, you can add an I parameter to get rid of them.
tree -iH http://lab.tianyizone.com/
Copy the code
I don’t think there’s a lot of HTML now, most of it is JSON, so we can do this.
tree -J
Copy the code
Does it feel convenient and quick? If you don’t feel that way, I can’t help it. Maybe I don’t need it. Personally, WHEN I was dealing with a small need, I got a lot of satisfaction and efficiency from this way.
Output to file
Now these operations, are displayed in the terminal, for we really need, it will not be displayed in the terminal, and then to select and copy, and finally to an editor paste, this is too troublesome. Even if we want to paste, we can at least do this:
tree -J | pbcopy
Copy the code
At least that’ll get you straight to the clipboard.
But I still feel bad about it. So that satisfies us with the -o argument.
tree -o tree.md
Copy the code
Now we can see the new MD file in the current directory.
Take a look at the contents of tree.md:
If you don’t like this command, you can use:
tree -J >> tree_json.js
Copy the code
In this way, it can also meet our needs.
And then check it out
Using >> appends content to a file. If you use >, the new content overwrites the previous content.
tree -H http://lab.tianyizone.com/ > tree_json.js
Copy the code
In this case, you can see that the previous JSON format content is gone. then
tree -J >> tree_json.js
Copy the code
If you do this once, the JSON content will fall behind the HTML format.
The last
In the tree, you can filter and display certain files by means of re. This has not been used, but it is not meaningful for a while. Specific how, good or not to use, this is radish green vegetables have their own love, after all, this command for me in fact, the use rate is not high, but really used, or very convenient.