This past week I gave a presentation at Day of Shecurity SF (check it out) about how to use sed, grep, awk, uniq, sort, and wc to do quick log analysis. This presentation kind of inspired me to share other random commands that I know or learn about. So, as I learn, I'll post little mini blogs about commands that I've found useful.
Today's command is
tree is almost never a native package on most Linux distros I've used, so you're more than likely have to install it but it is a great alternative for viewing files in a beautiful format. It's an easy command to remember because it shows you a tree diagram of files and directories.
why it's useful
- Ability to see sub directories and the files in them all in one view and in a clear way
Tree is a recursive directory listing program that produces a depth indented listing of files, which is colorized ala dircolors if the LS_COLORS environment variable is set and output is to tty. With no arguments, tree lists the files in the current directory.When directory arguments are given, tree lists all the files and/or directories found in the given directories each in turn. Upon completion of listing all files/directories found, tree returns the total number of files and/or directories listed.
$ man tree to view the full manual and flags that are available.
command line usage
Here's an example of
tree from the /var/log directory on my demo server. (I truncated the rules at the end.)
demo@demo-server:/var/log$ tree . ├── alternatives.log ├── apt │ ├── eipp.log.xz │ ├── history.log │ └── term.log ├── auth.log ├── bootstrap.log ├── btmp ├── cloud-init.log ├── cloud-init-output.log ├── dist-upgrade ├── dpkg.log ├── faillog ├── installer │ ├── block │ │ ├── discover.log │ │ └── probe-data.json │ ├── curtin-install-cfg.yaml │ ├── curtin-install.log │ ├── installer-journal.txt │ ├── media-info │ ├── subiquity-curtin-install.conf │ └── subiquity-debug.log . . . 9 directories, 37 files