Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 14, 2021 03:23 pm GMT

tree in Linux

tree in Linux

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 essentials in Linux

To install tree in Ubuntu, Debian Linux distros.

sudo apt-get install tree

To install tree in CentOS:

sudo yum install tree

In Windows, you can issue tree in Windows Terminal.

Enter tree

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

Man page

man tree

List all contents including hidden files and file starts with .

tree -a

List all directories recursively

tree -d

Print file patch prefix

tree -f

Print details by max display depth

tree -L 1

Display Depth 1

Print details by pattern

tree -P b*

Print details by pattern

tree backups -P 'SMTP*'

Print details by pattern
'*' - 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

Print details not matching the pattern

tree backups -I 'SMTP*'

Print details not matching the pattern

--matchdirs and --prune

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.

--matchdirs and --prune

--noreport

To not to print the file and directory report, use --noreport.

tree bin -P '*.log' --prune --noreport 

JSON Output

tree bin -P '*.log' --prune -J

XML Output

tree bin -P '*.log' --prune -X

Print last modification date/time

tree bin -P '*.log' --prune -D

Print size

tree bin/ -P '*.properties' --prune -h

Print size

Mark directories and files

-F marks directories as * and / for files.

tree -P '*.jmx' --prune -F

Mark directories and files

--dirsfirst

It displays directories first over files. To disable, use -U.

tree -P '*.jtl' --prune --dirsfirst

--dirsfirst

--dirsfirst

In this post, we have covered frequently used tree commands. Please check my blog for more such tutorials.

QAInsights YouTube Channel


Original Link: https://dev.to/qainsights/tree-in-linux-mpa

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To