Use `tree` instead of `ls` - 24/05/2023
Lorem ipsum dolor sit amet consectetur et ultrices blandit neque ege
Drop ls
for tree
in your day to day unix shell experience
You cd
into a huge directory- maybe you are at root looking for a certain config or file that is swallowed up by a sea of log files, dot-files, and other directories.
You run ls
and there you sit, scanning through the output with a keen eye trying to decide where to go next- the destination is unknown.
…or maybe instead you are refactoring a huge monolithic application and have spent quite a while refactoring and rearchitecting the organization of the app. You want to present it at standup or run it by someone for a second opinion.
tree
is a great tool that has many of the features of ls
with a much prettier print and can help you out in both of these predicaments- lets look at an example.
ls
. config.dat data data1.bin data2.sql data3.inf images background.jpg icon.gif logo.jpg program.exe readme.txt
tree
. ├── config.dat├── data│ ├── data1.bin│ ├── data2.sql│ └── data3.inf├── images│ ├── background.jpg│ ├── icon.gif│ └── logo.jpg├── program.exe└── readme.txt 2 directories, 9 files
And just like that, no more ls
for you. There are plenty of flags that are useful to expand or narrow down the tree that is returned, here are some I use often:
-a Print hidden dot files or “all”, akin to ls -a
-d List directories only
-f Prints the full path prefix for each file
-l Follows symbolic links if they point to directories, as if they were directories. Symbolic links that will result in recursion are avoided when detected.
Be sure to check out the manpage for all of the options and find new ways to make it suit your needs.
Always try and apply the tool in the ways that best help you solve your unique problem!
You can even alias
this command in your .bashrc
or .bashprofile
(or zsh/fish if you roll that way) and have just as short of a time \nalias t=tree\n
And maybe even have specific versions of it to list what you need using some flag commands like this one that will search a passed pattern
function tree_seek() {
tree -P \"*$1*\"
}
Hope that this helps you out- if you are on many flavors of linux you should already have, otherwise mac users I recommend downloading homebrew and installing with brew install tree
,
A dog-loving full stack developer and Marine veteran from New Haven, CT that thoroughly enjoys reading and sharing to solidify his own learning.__https://grandorimichael.medium.com/