tree command helps to recursively list the directory and its details in a tree format. In this post, we will see how you can use
tree effectively to view the directory details.
tree in Ubuntu, Debian Linux distros.
sudo apt-get install tree
tree in CentOS:
sudo yum install tree
In Windows, you can issue
tree in Windows Terminal.
If you enter
tree command without any arguments, it will list out everything from the current directory recursively. Suppose, if you are in your home directory, it will display everything recursively like below.
tree -L 1
tree -P b*
tree backups -P 'SMTP*'
'*' - any zero or more characters
'?' - any single character
'[...]' - any single character listed between brackets
'[A-Z]' - for range
'[^...]'- any single character not listed in brackets
'|' - separates alternate patterns
tree backups -I 'SMTP*'
If you use
-P which matches both the directories and files. If the match is found for directories, then the matching is disabled for its contents. Use it with --prune to prune it.
To not to print the file and directory report, use
tree bin -P '*.log' --prune --noreport
tree bin -P '*.log' --prune -J
tree bin -P '*.log' --prune -X
tree bin -P '*.log' --prune -D
tree bin/ -P '*.properties' --prune -h
-F marks directories as
/ for files.
tree -P '*.jmx' --prune -F
It displays directories first over files. To disable, use
tree -P '*.jtl' --prune --dirsfirst
In this post, we have covered frequently used tree commands. Please check my blog for more such tutorials.