Is there a command to get the maximum folder depth of entire system?
Short version: Is there a command and/or set of commands and/or utility to know what is the maximum depth of folders on my filesystem ?
Long version: I'm on Mac OS X. I'd like to know what is the deepest folder there is on my system (I don't care for access rights). This is because I want to launch a command on the root /
and it will be recursive and I don't want it to hang (unexpected results). So I need to know how many levels of folders there are between /
and the deepest folder.
I searched on Google and forums but couldn't find anything conclusive. I read that the HFS+ filesystem I'm using has no limit in depth, but maybe there is a limit in path name length ?
EDIT: Someone tried by filling up the fs but it's a dirty solution... I'd like a "cleaner" one if possible. Actually, finding the maximum depth on my actual system would be enough without testing out the limits.
Thanks for your help !
macos command-line
add a comment |
Short version: Is there a command and/or set of commands and/or utility to know what is the maximum depth of folders on my filesystem ?
Long version: I'm on Mac OS X. I'd like to know what is the deepest folder there is on my system (I don't care for access rights). This is because I want to launch a command on the root /
and it will be recursive and I don't want it to hang (unexpected results). So I need to know how many levels of folders there are between /
and the deepest folder.
I searched on Google and forums but couldn't find anything conclusive. I read that the HFS+ filesystem I'm using has no limit in depth, but maybe there is a limit in path name length ?
EDIT: Someone tried by filling up the fs but it's a dirty solution... I'd like a "cleaner" one if possible. Actually, finding the maximum depth on my actual system would be enough without testing out the limits.
Thanks for your help !
macos command-line
Note that the linked post determines the deepest possible path. You seem to be asking for the longest actually existing path.
– Daniel Beck♦
Nov 30 '13 at 19:48
Yes, I'm asking for the longest actually existing path. That link was the only thing I found on Google that was approximately what I was searching.
– achedeuzot
Nov 30 '13 at 20:04
add a comment |
Short version: Is there a command and/or set of commands and/or utility to know what is the maximum depth of folders on my filesystem ?
Long version: I'm on Mac OS X. I'd like to know what is the deepest folder there is on my system (I don't care for access rights). This is because I want to launch a command on the root /
and it will be recursive and I don't want it to hang (unexpected results). So I need to know how many levels of folders there are between /
and the deepest folder.
I searched on Google and forums but couldn't find anything conclusive. I read that the HFS+ filesystem I'm using has no limit in depth, but maybe there is a limit in path name length ?
EDIT: Someone tried by filling up the fs but it's a dirty solution... I'd like a "cleaner" one if possible. Actually, finding the maximum depth on my actual system would be enough without testing out the limits.
Thanks for your help !
macos command-line
Short version: Is there a command and/or set of commands and/or utility to know what is the maximum depth of folders on my filesystem ?
Long version: I'm on Mac OS X. I'd like to know what is the deepest folder there is on my system (I don't care for access rights). This is because I want to launch a command on the root /
and it will be recursive and I don't want it to hang (unexpected results). So I need to know how many levels of folders there are between /
and the deepest folder.
I searched on Google and forums but couldn't find anything conclusive. I read that the HFS+ filesystem I'm using has no limit in depth, but maybe there is a limit in path name length ?
EDIT: Someone tried by filling up the fs but it's a dirty solution... I'd like a "cleaner" one if possible. Actually, finding the maximum depth on my actual system would be enough without testing out the limits.
Thanks for your help !
macos command-line
macos command-line
asked Nov 30 '13 at 17:15
achedeuzotachedeuzot
1157
1157
Note that the linked post determines the deepest possible path. You seem to be asking for the longest actually existing path.
– Daniel Beck♦
Nov 30 '13 at 19:48
Yes, I'm asking for the longest actually existing path. That link was the only thing I found on Google that was approximately what I was searching.
– achedeuzot
Nov 30 '13 at 20:04
add a comment |
Note that the linked post determines the deepest possible path. You seem to be asking for the longest actually existing path.
– Daniel Beck♦
Nov 30 '13 at 19:48
Yes, I'm asking for the longest actually existing path. That link was the only thing I found on Google that was approximately what I was searching.
– achedeuzot
Nov 30 '13 at 20:04
Note that the linked post determines the deepest possible path. You seem to be asking for the longest actually existing path.
– Daniel Beck♦
Nov 30 '13 at 19:48
Note that the linked post determines the deepest possible path. You seem to be asking for the longest actually existing path.
– Daniel Beck♦
Nov 30 '13 at 19:48
Yes, I'm asking for the longest actually existing path. That link was the only thing I found on Google that was approximately what I was searching.
– achedeuzot
Nov 30 '13 at 20:04
Yes, I'm asking for the longest actually existing path. That link was the only thing I found on Google that was approximately what I was searching.
– achedeuzot
Nov 30 '13 at 20:04
add a comment |
3 Answers
3
active
oldest
votes
The following traverses your entire file system looking for directories only, removes everything that's not a forward slash (path item delimiter), and prints the longest trail (at least on my system, sort behavior may depend on locale).
find / -type d | sed 's|[^/]||g' | sort | tail -n1
Count the resulting slashes, which is one for every directory except root, so if the deepest directory path were /Users/danielbeck
, the result would be //
. Of course, there could be files in that directory.
yeah. that's better. :-)
– Sirex
Nov 30 '13 at 19:45
Great, I got//////////////////////////
if anyone is interested (that's 26 folders deep).
– achedeuzot
Nov 30 '13 at 20:01
add a comment |
Based on Daniel Beck's answer but for those who like counting machines
find / -type d | sed 's|[^/]||g' | sort | tail -n1 | egrep -i -o / | wc -l
If the deepest directory path were /Users/danielbeck
, the result would be 2
add a comment |
easiest way ?
mkdir /a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a
your deepest dir is now that.
less easy way ? Probably something like:
for i in `find .`; do echo $i | tr -d -c '/n' | wc -m >> /tmp/counts; done; sort -nr /tmp/counts | head -n 1
i.e: show all file paths, rips out anything that isn't /. Count how many there were, then show the highest number.
something like that - feel free to improve it, pretty sure the /tmp file can be avoided using an in-memory file of some sort.
When I tried it, it somehow stopped after some time and went unresponsive... Thanks for the idea !
– achedeuzot
Nov 30 '13 at 20:02
This will break if any path contains a space in its name. Don't parse the output offind
orls
: mywiki.wooledge.org/ParsingLs
– slhck
Nov 30 '13 at 20:22
Yeah, it sucks. I know. Personally I'd just do the mkdir and move onto the next problem.
– Sirex
Dec 1 '13 at 4:47
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fsuperuser.com%2fquestions%2f682483%2fis-there-a-command-to-get-the-maximum-folder-depth-of-entire-system%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
The following traverses your entire file system looking for directories only, removes everything that's not a forward slash (path item delimiter), and prints the longest trail (at least on my system, sort behavior may depend on locale).
find / -type d | sed 's|[^/]||g' | sort | tail -n1
Count the resulting slashes, which is one for every directory except root, so if the deepest directory path were /Users/danielbeck
, the result would be //
. Of course, there could be files in that directory.
yeah. that's better. :-)
– Sirex
Nov 30 '13 at 19:45
Great, I got//////////////////////////
if anyone is interested (that's 26 folders deep).
– achedeuzot
Nov 30 '13 at 20:01
add a comment |
The following traverses your entire file system looking for directories only, removes everything that's not a forward slash (path item delimiter), and prints the longest trail (at least on my system, sort behavior may depend on locale).
find / -type d | sed 's|[^/]||g' | sort | tail -n1
Count the resulting slashes, which is one for every directory except root, so if the deepest directory path were /Users/danielbeck
, the result would be //
. Of course, there could be files in that directory.
yeah. that's better. :-)
– Sirex
Nov 30 '13 at 19:45
Great, I got//////////////////////////
if anyone is interested (that's 26 folders deep).
– achedeuzot
Nov 30 '13 at 20:01
add a comment |
The following traverses your entire file system looking for directories only, removes everything that's not a forward slash (path item delimiter), and prints the longest trail (at least on my system, sort behavior may depend on locale).
find / -type d | sed 's|[^/]||g' | sort | tail -n1
Count the resulting slashes, which is one for every directory except root, so if the deepest directory path were /Users/danielbeck
, the result would be //
. Of course, there could be files in that directory.
The following traverses your entire file system looking for directories only, removes everything that's not a forward slash (path item delimiter), and prints the longest trail (at least on my system, sort behavior may depend on locale).
find / -type d | sed 's|[^/]||g' | sort | tail -n1
Count the resulting slashes, which is one for every directory except root, so if the deepest directory path were /Users/danielbeck
, the result would be //
. Of course, there could be files in that directory.
answered Nov 30 '13 at 19:43
Daniel Beck♦Daniel Beck
92.6k12232286
92.6k12232286
yeah. that's better. :-)
– Sirex
Nov 30 '13 at 19:45
Great, I got//////////////////////////
if anyone is interested (that's 26 folders deep).
– achedeuzot
Nov 30 '13 at 20:01
add a comment |
yeah. that's better. :-)
– Sirex
Nov 30 '13 at 19:45
Great, I got//////////////////////////
if anyone is interested (that's 26 folders deep).
– achedeuzot
Nov 30 '13 at 20:01
yeah. that's better. :-)
– Sirex
Nov 30 '13 at 19:45
yeah. that's better. :-)
– Sirex
Nov 30 '13 at 19:45
Great, I got
//////////////////////////
if anyone is interested (that's 26 folders deep).– achedeuzot
Nov 30 '13 at 20:01
Great, I got
//////////////////////////
if anyone is interested (that's 26 folders deep).– achedeuzot
Nov 30 '13 at 20:01
add a comment |
Based on Daniel Beck's answer but for those who like counting machines
find / -type d | sed 's|[^/]||g' | sort | tail -n1 | egrep -i -o / | wc -l
If the deepest directory path were /Users/danielbeck
, the result would be 2
add a comment |
Based on Daniel Beck's answer but for those who like counting machines
find / -type d | sed 's|[^/]||g' | sort | tail -n1 | egrep -i -o / | wc -l
If the deepest directory path were /Users/danielbeck
, the result would be 2
add a comment |
Based on Daniel Beck's answer but for those who like counting machines
find / -type d | sed 's|[^/]||g' | sort | tail -n1 | egrep -i -o / | wc -l
If the deepest directory path were /Users/danielbeck
, the result would be 2
Based on Daniel Beck's answer but for those who like counting machines
find / -type d | sed 's|[^/]||g' | sort | tail -n1 | egrep -i -o / | wc -l
If the deepest directory path were /Users/danielbeck
, the result would be 2
answered Jan 14 at 9:57
Jack.LJack.L
112
112
add a comment |
add a comment |
easiest way ?
mkdir /a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a
your deepest dir is now that.
less easy way ? Probably something like:
for i in `find .`; do echo $i | tr -d -c '/n' | wc -m >> /tmp/counts; done; sort -nr /tmp/counts | head -n 1
i.e: show all file paths, rips out anything that isn't /. Count how many there were, then show the highest number.
something like that - feel free to improve it, pretty sure the /tmp file can be avoided using an in-memory file of some sort.
When I tried it, it somehow stopped after some time and went unresponsive... Thanks for the idea !
– achedeuzot
Nov 30 '13 at 20:02
This will break if any path contains a space in its name. Don't parse the output offind
orls
: mywiki.wooledge.org/ParsingLs
– slhck
Nov 30 '13 at 20:22
Yeah, it sucks. I know. Personally I'd just do the mkdir and move onto the next problem.
– Sirex
Dec 1 '13 at 4:47
add a comment |
easiest way ?
mkdir /a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a
your deepest dir is now that.
less easy way ? Probably something like:
for i in `find .`; do echo $i | tr -d -c '/n' | wc -m >> /tmp/counts; done; sort -nr /tmp/counts | head -n 1
i.e: show all file paths, rips out anything that isn't /. Count how many there were, then show the highest number.
something like that - feel free to improve it, pretty sure the /tmp file can be avoided using an in-memory file of some sort.
When I tried it, it somehow stopped after some time and went unresponsive... Thanks for the idea !
– achedeuzot
Nov 30 '13 at 20:02
This will break if any path contains a space in its name. Don't parse the output offind
orls
: mywiki.wooledge.org/ParsingLs
– slhck
Nov 30 '13 at 20:22
Yeah, it sucks. I know. Personally I'd just do the mkdir and move onto the next problem.
– Sirex
Dec 1 '13 at 4:47
add a comment |
easiest way ?
mkdir /a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a
your deepest dir is now that.
less easy way ? Probably something like:
for i in `find .`; do echo $i | tr -d -c '/n' | wc -m >> /tmp/counts; done; sort -nr /tmp/counts | head -n 1
i.e: show all file paths, rips out anything that isn't /. Count how many there were, then show the highest number.
something like that - feel free to improve it, pretty sure the /tmp file can be avoided using an in-memory file of some sort.
easiest way ?
mkdir /a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a
your deepest dir is now that.
less easy way ? Probably something like:
for i in `find .`; do echo $i | tr -d -c '/n' | wc -m >> /tmp/counts; done; sort -nr /tmp/counts | head -n 1
i.e: show all file paths, rips out anything that isn't /. Count how many there were, then show the highest number.
something like that - feel free to improve it, pretty sure the /tmp file can be avoided using an in-memory file of some sort.
edited Nov 30 '13 at 19:38
answered Nov 30 '13 at 19:32
SirexSirex
9,72843252
9,72843252
When I tried it, it somehow stopped after some time and went unresponsive... Thanks for the idea !
– achedeuzot
Nov 30 '13 at 20:02
This will break if any path contains a space in its name. Don't parse the output offind
orls
: mywiki.wooledge.org/ParsingLs
– slhck
Nov 30 '13 at 20:22
Yeah, it sucks. I know. Personally I'd just do the mkdir and move onto the next problem.
– Sirex
Dec 1 '13 at 4:47
add a comment |
When I tried it, it somehow stopped after some time and went unresponsive... Thanks for the idea !
– achedeuzot
Nov 30 '13 at 20:02
This will break if any path contains a space in its name. Don't parse the output offind
orls
: mywiki.wooledge.org/ParsingLs
– slhck
Nov 30 '13 at 20:22
Yeah, it sucks. I know. Personally I'd just do the mkdir and move onto the next problem.
– Sirex
Dec 1 '13 at 4:47
When I tried it, it somehow stopped after some time and went unresponsive... Thanks for the idea !
– achedeuzot
Nov 30 '13 at 20:02
When I tried it, it somehow stopped after some time and went unresponsive... Thanks for the idea !
– achedeuzot
Nov 30 '13 at 20:02
This will break if any path contains a space in its name. Don't parse the output of
find
or ls
: mywiki.wooledge.org/ParsingLs– slhck
Nov 30 '13 at 20:22
This will break if any path contains a space in its name. Don't parse the output of
find
or ls
: mywiki.wooledge.org/ParsingLs– slhck
Nov 30 '13 at 20:22
Yeah, it sucks. I know. Personally I'd just do the mkdir and move onto the next problem.
– Sirex
Dec 1 '13 at 4:47
Yeah, it sucks. I know. Personally I'd just do the mkdir and move onto the next problem.
– Sirex
Dec 1 '13 at 4:47
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f682483%2fis-there-a-command-to-get-the-maximum-folder-depth-of-entire-system%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
Note that the linked post determines the deepest possible path. You seem to be asking for the longest actually existing path.
– Daniel Beck♦
Nov 30 '13 at 19:48
Yes, I'm asking for the longest actually existing path. That link was the only thing I found on Google that was approximately what I was searching.
– achedeuzot
Nov 30 '13 at 20:04