- Read Tutorial
- Watch Guide Video
As a developer, another tool that I find completely invaluable is the ability to very quickly see the entire file tree if I pass a path to it. So in other words, and I already have this installed, so I'll show you how it works.
Right now I am in this Rails application. If I wanna see the entire file system for this, I can simply type in tree and this is going to show me the entire file system and it shows it to me in kinda this cool looking kind of tree structure.
I could also pass this an argument of a path. So I could say tree, app, views and this show me all of the available views.
Yes, obviously I could do this inside of the finder and I could also just open vim up and see it on the left-hand side using NERDTree, but there are many times where I'll have a question about a file name and I don't wanna open vim up in order to do it and I definitely don't wanna open up the finder, that wouldn't be very intuitive or very efficient at all.
So this tree commands makes it incredibly easy to see the full set of files that I have and I can also pass a path to it. This can be a very messy tree if you tried to do it like you saw a little while ago when I tried to pass it to the entire application. For example, watch what happens if I were to do this in the Dev Camp site itself.
So if I do Dev Camp, and pass tree to it, you can see all kinds of files because this shows the cache files, you could... there's probably about a million different files in here and that's the reason why it's so important to do tree and then if I wanna do tree, app, views, then this makes it a little bit more efficient. It's pretty rare that I'll just type tree in, I usually also pass some type of path to it.
Now if you do not have this installed, the easiest way to do it is to use Homebrew and I'm assuming you have Homebrew installed. If you do not, that's perfectly fine, you can go to brew.sh and simply type this, or copy this code right here, and paste it and you'll be good to go and you'll be able to install any kind of application via Homebrew.
I'm assuming if you gotten this far that you probably already have Homebrew installed, but just incase, or if you came from Windows or Linux or something like that, then Homebrew is kinda the standard way to manage dependencies in Mac.
So the way that we're gonna install tree, is to type brew, install, tree and now if I hit return. This is gonna go out to Homebrew and it's going to find all of the various dependencies that are needed. We can see right away it updates Homebrew, that's the first thing that it does and depending on how long it's been since you updated Homebrew, this could take, who knows how long, a few minutes to a few seconds.
I already have tree installed and that's why it said tree already installed, but this shows all of the various items that I've installed via Homebrew throughout the years.
So if you didn't already have tree installed, then this would give you a full list of output and it may take a few minutes in order to install, but now that it is, navigate anywhere in your application, type in tree, and now you'll have access to see the entire tree system, which is incredibly helpful. And if you take my advanced Ruby course, I use that quite a bit whenever I'm trying to do something like say I'm creating a generator in Ruby, say I'm creating a gem or something like that, then I don't wanna have to navigate and see did my generator work. I can just type in tree and it'll show me all the files that were created, so it's a much more efficient way of being able to see all of that.