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 tr…


This content originally appeared on DEV Community and was authored by NaveenKumar Namachivayam ⚡

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


This content originally appeared on DEV Community and was authored by NaveenKumar Namachivayam ⚡


Print Share Comment Cite Upload Translate Updates
APA

NaveenKumar Namachivayam ⚡ | Sciencx (2021-06-14T15:23:22+00:00) tree in Linux. Retrieved from https://www.scien.cx/2021/06/14/tree-in-linux/

MLA
" » tree in Linux." NaveenKumar Namachivayam ⚡ | Sciencx - Monday June 14, 2021, https://www.scien.cx/2021/06/14/tree-in-linux/
HARVARD
NaveenKumar Namachivayam ⚡ | Sciencx Monday June 14, 2021 » tree in Linux., viewed ,<https://www.scien.cx/2021/06/14/tree-in-linux/>
VANCOUVER
NaveenKumar Namachivayam ⚡ | Sciencx - » tree in Linux. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/14/tree-in-linux/
CHICAGO
" » tree in Linux." NaveenKumar Namachivayam ⚡ | Sciencx - Accessed . https://www.scien.cx/2021/06/14/tree-in-linux/
IEEE
" » tree in Linux." NaveenKumar Namachivayam ⚡ | Sciencx [Online]. Available: https://www.scien.cx/2021/06/14/tree-in-linux/. [Accessed: ]
rf:citation
» tree in Linux | NaveenKumar Namachivayam ⚡ | Sciencx | https://www.scien.cx/2021/06/14/tree-in-linux/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.