Can tree be used to list the number of files per level?
Clash Royale CLAN TAG#URR8PPP
I need to look into a particular directory and list the number of files per level. The directory is pretty large, about 10-15 levels deep. For instance, if I have the following:
D1
|
|-- D2A (5 files in this directory)
| |-- D3A (6 files in this directory)
| |-- D3B (7 Files in this directory)
|
|-- D2B (1 file in this directory)
Then it should tell me that level 3 has 13 files and level 2 has 6 files (or 6+13, doesn't matter). Can Tree
accomplish this? I've tried around mixing the options but it does not seem to work.
directory directory-structure tree
add a comment |
I need to look into a particular directory and list the number of files per level. The directory is pretty large, about 10-15 levels deep. For instance, if I have the following:
D1
|
|-- D2A (5 files in this directory)
| |-- D3A (6 files in this directory)
| |-- D3B (7 Files in this directory)
|
|-- D2B (1 file in this directory)
Then it should tell me that level 3 has 13 files and level 2 has 6 files (or 6+13, doesn't matter). Can Tree
accomplish this? I've tried around mixing the options but it does not seem to work.
directory directory-structure tree
tree
can't do this.
– slm♦
Oct 14 '13 at 11:44
add a comment |
I need to look into a particular directory and list the number of files per level. The directory is pretty large, about 10-15 levels deep. For instance, if I have the following:
D1
|
|-- D2A (5 files in this directory)
| |-- D3A (6 files in this directory)
| |-- D3B (7 Files in this directory)
|
|-- D2B (1 file in this directory)
Then it should tell me that level 3 has 13 files and level 2 has 6 files (or 6+13, doesn't matter). Can Tree
accomplish this? I've tried around mixing the options but it does not seem to work.
directory directory-structure tree
I need to look into a particular directory and list the number of files per level. The directory is pretty large, about 10-15 levels deep. For instance, if I have the following:
D1
|
|-- D2A (5 files in this directory)
| |-- D3A (6 files in this directory)
| |-- D3B (7 Files in this directory)
|
|-- D2B (1 file in this directory)
Then it should tell me that level 3 has 13 files and level 2 has 6 files (or 6+13, doesn't matter). Can Tree
accomplish this? I've tried around mixing the options but it does not seem to work.
directory directory-structure tree
directory directory-structure tree
edited Feb 10 at 19:23
Rui F Ribeiro
41.1k1479137
41.1k1479137
asked Oct 14 '13 at 9:41
gohgoh
1133
1133
tree
can't do this.
– slm♦
Oct 14 '13 at 11:44
add a comment |
tree
can't do this.
– slm♦
Oct 14 '13 at 11:44
tree
can't do this.– slm♦
Oct 14 '13 at 11:44
tree
can't do this.– slm♦
Oct 14 '13 at 11:44
add a comment |
3 Answers
3
active
oldest
votes
find . -type d |
perl -ne 'BEGIN sub cnt $file=shift; $c="find $file -maxdepth 1 -type f chomp; printf "%s %sn", $_, cnt($_)' |
perl -ne '/^(.*) (d*)$/; $_scalar(split ///, $1)+=$2; END printf "Depth %d has %d files.n", @$_ for map [$_,$_$_] sort keys %_ '
Results:
Depth 1 has 7 files.
Depth 2 has 2353 files.
Depth 3 has 2558 files.
Depth 4 has 8242 files.
Depth 5 has 6452 files.
Depth 6 has 674 files.
Depth 7 has 1112 files.
Depth 8 has 64 files.
Depth 9 has 154 files.
add a comment |
tree | sed 's/ //g;s/`/|/g;s/-.*//g' | sort | uniq -c | grep |
Results:
35 |
186 ||
1408 |||
691 ||||
The pipe (|) character indicates the depth.
add a comment |
I doubt if tree
can accomplish this. However, find
can:
find . -mindepth 3 -maxdepth 3 -type f | wc -l
would return the number of files at level 3.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f95976%2fcan-tree-be-used-to-list-the-number-of-files-per-level%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
find . -type d |
perl -ne 'BEGIN sub cnt $file=shift; $c="find $file -maxdepth 1 -type f chomp; printf "%s %sn", $_, cnt($_)' |
perl -ne '/^(.*) (d*)$/; $_scalar(split ///, $1)+=$2; END printf "Depth %d has %d files.n", @$_ for map [$_,$_$_] sort keys %_ '
Results:
Depth 1 has 7 files.
Depth 2 has 2353 files.
Depth 3 has 2558 files.
Depth 4 has 8242 files.
Depth 5 has 6452 files.
Depth 6 has 674 files.
Depth 7 has 1112 files.
Depth 8 has 64 files.
Depth 9 has 154 files.
add a comment |
find . -type d |
perl -ne 'BEGIN sub cnt $file=shift; $c="find $file -maxdepth 1 -type f chomp; printf "%s %sn", $_, cnt($_)' |
perl -ne '/^(.*) (d*)$/; $_scalar(split ///, $1)+=$2; END printf "Depth %d has %d files.n", @$_ for map [$_,$_$_] sort keys %_ '
Results:
Depth 1 has 7 files.
Depth 2 has 2353 files.
Depth 3 has 2558 files.
Depth 4 has 8242 files.
Depth 5 has 6452 files.
Depth 6 has 674 files.
Depth 7 has 1112 files.
Depth 8 has 64 files.
Depth 9 has 154 files.
add a comment |
find . -type d |
perl -ne 'BEGIN sub cnt $file=shift; $c="find $file -maxdepth 1 -type f chomp; printf "%s %sn", $_, cnt($_)' |
perl -ne '/^(.*) (d*)$/; $_scalar(split ///, $1)+=$2; END printf "Depth %d has %d files.n", @$_ for map [$_,$_$_] sort keys %_ '
Results:
Depth 1 has 7 files.
Depth 2 has 2353 files.
Depth 3 has 2558 files.
Depth 4 has 8242 files.
Depth 5 has 6452 files.
Depth 6 has 674 files.
Depth 7 has 1112 files.
Depth 8 has 64 files.
Depth 9 has 154 files.
find . -type d |
perl -ne 'BEGIN sub cnt $file=shift; $c="find $file -maxdepth 1 -type f chomp; printf "%s %sn", $_, cnt($_)' |
perl -ne '/^(.*) (d*)$/; $_scalar(split ///, $1)+=$2; END printf "Depth %d has %d files.n", @$_ for map [$_,$_$_] sort keys %_ '
Results:
Depth 1 has 7 files.
Depth 2 has 2353 files.
Depth 3 has 2558 files.
Depth 4 has 8242 files.
Depth 5 has 6452 files.
Depth 6 has 674 files.
Depth 7 has 1112 files.
Depth 8 has 64 files.
Depth 9 has 154 files.
answered Oct 14 '13 at 14:26
Stach JankowskiStach Jankowski
361
361
add a comment |
add a comment |
tree | sed 's/ //g;s/`/|/g;s/-.*//g' | sort | uniq -c | grep |
Results:
35 |
186 ||
1408 |||
691 ||||
The pipe (|) character indicates the depth.
add a comment |
tree | sed 's/ //g;s/`/|/g;s/-.*//g' | sort | uniq -c | grep |
Results:
35 |
186 ||
1408 |||
691 ||||
The pipe (|) character indicates the depth.
add a comment |
tree | sed 's/ //g;s/`/|/g;s/-.*//g' | sort | uniq -c | grep |
Results:
35 |
186 ||
1408 |||
691 ||||
The pipe (|) character indicates the depth.
tree | sed 's/ //g;s/`/|/g;s/-.*//g' | sort | uniq -c | grep |
Results:
35 |
186 ||
1408 |||
691 ||||
The pipe (|) character indicates the depth.
answered Oct 14 '13 at 19:15
jamespfinnjamespfinn
35816
35816
add a comment |
add a comment |
I doubt if tree
can accomplish this. However, find
can:
find . -mindepth 3 -maxdepth 3 -type f | wc -l
would return the number of files at level 3.
add a comment |
I doubt if tree
can accomplish this. However, find
can:
find . -mindepth 3 -maxdepth 3 -type f | wc -l
would return the number of files at level 3.
add a comment |
I doubt if tree
can accomplish this. However, find
can:
find . -mindepth 3 -maxdepth 3 -type f | wc -l
would return the number of files at level 3.
I doubt if tree
can accomplish this. However, find
can:
find . -mindepth 3 -maxdepth 3 -type f | wc -l
would return the number of files at level 3.
answered Oct 14 '13 at 10:12
devnulldevnull
8,68112942
8,68112942
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f95976%2fcan-tree-be-used-to-list-the-number-of-files-per-level%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
tree
can't do this.– slm♦
Oct 14 '13 at 11:44