Questions tagged [tree]
112 questions
15
votes
4 answers
How to make tree output only files?
tree has a -d option to "List directories only.". However, I cannot seem to find an option to "List files only." I have looked through the man page, but I cannot seem to find an option for listing only files.

stiemannkj1
- 303
4
votes
1 answer
tree command with 'sort=size' seems imperfect
I'm trying to sort by size:
% tree -axCF --du --sort=size | grep -e '/$'
├── [ 8658884] 2022-10-09-backup/
├── [ 5923934] f24-01-22-backup/
├── [ 5384825] e2023-01-19-backup/
├── [ 3627525] h24-01-22-npanelize-nselect/
├── [ …

Ray Andrews
- 2,347
4
votes
1 answer
Is there a way to make tree not show the top level?
By default, tree shows this:
$ tree
.
├── Package.resolved
├── Package.swift
├── Sources
│ └── SwiftClientSDK
│ ├── OpenAPI.yaml
│ ├── SwiftClientSDK.swift
│ └── openapi-generator-config.yaml
└── Tests
└──…

Rick
- 205
2
votes
0 answers
Is it possible to colourise the heading lines on bash tree output?
Say I have a directory structure that looks like this:
foo
|-- bar
| |-- 1
| |-- 2
| |-- 3
| |-- baz
| | |-- 4
| | |-- 5
| | |-- 6
| | |-- moo
| | | |-- 7
| | | |-- 8
| | | |-- 9
| | | `-- mar
| | …

Lou
- 205
2
votes
2 answers
How to use the tree command to expand only selected folder(s)?
I'm creating a script that generates a project folder into another folder along with some other module folders. I want to show how the generated project folder structure looks in the final tree but avoid the expansion of all other folders so the…

m4l490n
- 175
1
vote
1 answer
Tree display hw, hw.cpp & hw.cpp2 in sub-directories
I would like tree to display the hw files in the sub-directories like this:
.
├── exp
│ └── hw
├── src
│ └── hw.cpp2
└── tmp
└── hw.cpp
$ /usr/bin/tree --noreport . displays all of the files:
.
├── exp
│ ├── hi
│ └── hw
├── src
│ ├──…

CW Holeman II
- 3,684
1
vote
1 answer
tree command to only output file and directory count?
I want to keep only the last line of tree's output or the file+directory count report. Preferably, with the -a switch.
An example output I desire:
585 directories, 37722 files
Is this possible with tree?

Sepp A
- 63
1
vote
0 answers
tree command how to omit too many subfolders?
I want to preview the structure of a folder with tree -d. However, some subfolder has too many subfolders, which prevent me to preview the whole tree at a glance, so I want a argument such as --maxSubfolders 8, which makes the leftover displays an…

DawnSong
- 113
- 4
1
vote
1 answer
Why does 'tree' command ignore directories but not files
tree shows
...
│ ├── template_one_file.sh
│ ├── template_sed.sh
│ ├── testy.sh
│ ├── tmp
│ │ ├── file1.html.13567_old
│ │ ├── file2.html.13567_old
│ │ ├── file3.html.13567_old
│ │ └── file4.html.13567_old
│ └──…

Michael Durrant
- 42,013
1
vote
1 answer
Getting tree to only list files matching a pattern and the directories they are contained in
Is there anyway to get tree to behave such that, when it is run with the -P option, it will not output directories that don't have files matching the pattern somewhere inside of them?
As an example, take this directory structure:
${DIRECTORY}/
…

Melab
- 4,048
0
votes
1 answer
Command "tree -J" returns invalid Json
I gave the command tree -J to my machine, and this is a portion of the output it gave:
{
"type": "file",
"name": "ca-certificates.conf"
},
{
…
0
votes
0 answers
Ambiguous output from tree with respect to symbolic links
Whenever I use command line tools, I like to make sure that the output can be interpreted unambiguously. On one of my other machines, I wrote a shell script that would find all of the symbolic links residing under a particular path and it would…

Melab
- 4,048
0
votes
2 answers
Statistics for project filestypes
I learnt that there was a command cloc to count lines of code. Now I wonder if it the file types are accurate? Should I look a the cloc project to know how file types are detected? The reason I wonder is that cloc seems to have false positives if…

Niklas Rosencrantz
- 4,228
-2
votes
1 answer
Removing Folders from Linux Tree View?
Question: Is there a way to remove the display of certain folders from the linux tree command?
In my case, I'd like to be able to run something like
$ tree . --remove-dir=pictures
which will remove all directories entitled "pictures" from the tree…

George
- 1,809