Identifying the deepest folder in the tree

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
-4
down vote

favorite












Note - please don't downvote me because of the image. Its not a code in the image, its just a diagram which can be easily visualised there.



As you can see in this image, the deepest directory is "n2" within "a" --> https://imgur.com/a/jzzbm .



With the script/command/cmdlet/program, I want to programmatically find out the deepest folder within a given folder and be able to navigate into it (or print the absolute path of that deepest folder!).



Any help on how could this be achieved is appreciated.










share|improve this question



















  • 1




    Given the image is clearly text, what prevents you from copying the text here and using code formatting like I did in my answer to your previous question?
    – muru
    Apr 10 at 7:15










  • hey man i get your annoyance. But when I tried to paste it as it is, it looked horrible and not in the format. I quickly glanced over the formatting tips but couldnt figure it out.
    – Nish
    Apr 10 at 7:29










  • See askubuntu.com/editing-help#code on how to format code and output.
    – muru
    Apr 10 at 7:32






  • 1




    @Nish Please do paste the text into your question, select it, and press Ctrl+K to format it as code so it looks correct. That will make this question considerably better.
    – Eliah Kagan
    Apr 12 at 16:46














up vote
-4
down vote

favorite












Note - please don't downvote me because of the image. Its not a code in the image, its just a diagram which can be easily visualised there.



As you can see in this image, the deepest directory is "n2" within "a" --> https://imgur.com/a/jzzbm .



With the script/command/cmdlet/program, I want to programmatically find out the deepest folder within a given folder and be able to navigate into it (or print the absolute path of that deepest folder!).



Any help on how could this be achieved is appreciated.










share|improve this question



















  • 1




    Given the image is clearly text, what prevents you from copying the text here and using code formatting like I did in my answer to your previous question?
    – muru
    Apr 10 at 7:15










  • hey man i get your annoyance. But when I tried to paste it as it is, it looked horrible and not in the format. I quickly glanced over the formatting tips but couldnt figure it out.
    – Nish
    Apr 10 at 7:29










  • See askubuntu.com/editing-help#code on how to format code and output.
    – muru
    Apr 10 at 7:32






  • 1




    @Nish Please do paste the text into your question, select it, and press Ctrl+K to format it as code so it looks correct. That will make this question considerably better.
    – Eliah Kagan
    Apr 12 at 16:46












up vote
-4
down vote

favorite









up vote
-4
down vote

favorite











Note - please don't downvote me because of the image. Its not a code in the image, its just a diagram which can be easily visualised there.



As you can see in this image, the deepest directory is "n2" within "a" --> https://imgur.com/a/jzzbm .



With the script/command/cmdlet/program, I want to programmatically find out the deepest folder within a given folder and be able to navigate into it (or print the absolute path of that deepest folder!).



Any help on how could this be achieved is appreciated.










share|improve this question















Note - please don't downvote me because of the image. Its not a code in the image, its just a diagram which can be easily visualised there.



As you can see in this image, the deepest directory is "n2" within "a" --> https://imgur.com/a/jzzbm .



With the script/command/cmdlet/program, I want to programmatically find out the deepest folder within a given folder and be able to navigate into it (or print the absolute path of that deepest folder!).



Any help on how could this be achieved is appreciated.







command-line bash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 10 at 7:19









muru

130k19273463




130k19273463










asked Apr 10 at 7:02









Nish

483




483







  • 1




    Given the image is clearly text, what prevents you from copying the text here and using code formatting like I did in my answer to your previous question?
    – muru
    Apr 10 at 7:15










  • hey man i get your annoyance. But when I tried to paste it as it is, it looked horrible and not in the format. I quickly glanced over the formatting tips but couldnt figure it out.
    – Nish
    Apr 10 at 7:29










  • See askubuntu.com/editing-help#code on how to format code and output.
    – muru
    Apr 10 at 7:32






  • 1




    @Nish Please do paste the text into your question, select it, and press Ctrl+K to format it as code so it looks correct. That will make this question considerably better.
    – Eliah Kagan
    Apr 12 at 16:46












  • 1




    Given the image is clearly text, what prevents you from copying the text here and using code formatting like I did in my answer to your previous question?
    – muru
    Apr 10 at 7:15










  • hey man i get your annoyance. But when I tried to paste it as it is, it looked horrible and not in the format. I quickly glanced over the formatting tips but couldnt figure it out.
    – Nish
    Apr 10 at 7:29










  • See askubuntu.com/editing-help#code on how to format code and output.
    – muru
    Apr 10 at 7:32






  • 1




    @Nish Please do paste the text into your question, select it, and press Ctrl+K to format it as code so it looks correct. That will make this question considerably better.
    – Eliah Kagan
    Apr 12 at 16:46







1




1




Given the image is clearly text, what prevents you from copying the text here and using code formatting like I did in my answer to your previous question?
– muru
Apr 10 at 7:15




Given the image is clearly text, what prevents you from copying the text here and using code formatting like I did in my answer to your previous question?
– muru
Apr 10 at 7:15












hey man i get your annoyance. But when I tried to paste it as it is, it looked horrible and not in the format. I quickly glanced over the formatting tips but couldnt figure it out.
– Nish
Apr 10 at 7:29




hey man i get your annoyance. But when I tried to paste it as it is, it looked horrible and not in the format. I quickly glanced over the formatting tips but couldnt figure it out.
– Nish
Apr 10 at 7:29












See askubuntu.com/editing-help#code on how to format code and output.
– muru
Apr 10 at 7:32




See askubuntu.com/editing-help#code on how to format code and output.
– muru
Apr 10 at 7:32




1




1




@Nish Please do paste the text into your question, select it, and press Ctrl+K to format it as code so it looks correct. That will make this question considerably better.
– Eliah Kagan
Apr 12 at 16:46




@Nish Please do paste the text into your question, select it, and press Ctrl+K to format it as code so it looks correct. That will make this question considerably better.
– Eliah Kagan
Apr 12 at 16:46










1 Answer
1






active

oldest

votes

















up vote
1
down vote













Using find, sort and sed:



find . -type d -printf '%d %p' | sort -zrn | sed -z 's/[0-9]* //; q'


  • With find:

    • looking for directories (-type d)


    • %d and %p are the depth and name (including path)



  • sort sorts the lines numerically, in reverse

  • with sed, strip the leading depth, and quit after the first line, leaving just the path of the directory with the greatest depth

So:



cd "$(find . -type d -printf '%d %p' | sort -zrn | sed -z 's/[0-9]* //; q')"





share|improve this answer




















  • thanks for this. Appreciate your help in understanding the statement.
    – Nish
    Apr 10 at 7:33










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
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',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1023538%2fidentifying-the-deepest-folder-in-the-tree%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













Using find, sort and sed:



find . -type d -printf '%d %p' | sort -zrn | sed -z 's/[0-9]* //; q'


  • With find:

    • looking for directories (-type d)


    • %d and %p are the depth and name (including path)



  • sort sorts the lines numerically, in reverse

  • with sed, strip the leading depth, and quit after the first line, leaving just the path of the directory with the greatest depth

So:



cd "$(find . -type d -printf '%d %p' | sort -zrn | sed -z 's/[0-9]* //; q')"





share|improve this answer




















  • thanks for this. Appreciate your help in understanding the statement.
    – Nish
    Apr 10 at 7:33














up vote
1
down vote













Using find, sort and sed:



find . -type d -printf '%d %p' | sort -zrn | sed -z 's/[0-9]* //; q'


  • With find:

    • looking for directories (-type d)


    • %d and %p are the depth and name (including path)



  • sort sorts the lines numerically, in reverse

  • with sed, strip the leading depth, and quit after the first line, leaving just the path of the directory with the greatest depth

So:



cd "$(find . -type d -printf '%d %p' | sort -zrn | sed -z 's/[0-9]* //; q')"





share|improve this answer




















  • thanks for this. Appreciate your help in understanding the statement.
    – Nish
    Apr 10 at 7:33












up vote
1
down vote










up vote
1
down vote









Using find, sort and sed:



find . -type d -printf '%d %p' | sort -zrn | sed -z 's/[0-9]* //; q'


  • With find:

    • looking for directories (-type d)


    • %d and %p are the depth and name (including path)



  • sort sorts the lines numerically, in reverse

  • with sed, strip the leading depth, and quit after the first line, leaving just the path of the directory with the greatest depth

So:



cd "$(find . -type d -printf '%d %p' | sort -zrn | sed -z 's/[0-9]* //; q')"





share|improve this answer












Using find, sort and sed:



find . -type d -printf '%d %p' | sort -zrn | sed -z 's/[0-9]* //; q'


  • With find:

    • looking for directories (-type d)


    • %d and %p are the depth and name (including path)



  • sort sorts the lines numerically, in reverse

  • with sed, strip the leading depth, and quit after the first line, leaving just the path of the directory with the greatest depth

So:



cd "$(find . -type d -printf '%d %p' | sort -zrn | sed -z 's/[0-9]* //; q')"






share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 10 at 7:18









muru

130k19273463




130k19273463











  • thanks for this. Appreciate your help in understanding the statement.
    – Nish
    Apr 10 at 7:33
















  • thanks for this. Appreciate your help in understanding the statement.
    – Nish
    Apr 10 at 7:33















thanks for this. Appreciate your help in understanding the statement.
– Nish
Apr 10 at 7:33




thanks for this. Appreciate your help in understanding the statement.
– Nish
Apr 10 at 7:33

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1023538%2fidentifying-the-deepest-folder-in-the-tree%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Which professions warranted travel in Medieval times?

How do so many people here on Academia.SE, and in general, afford lavish higher education programs?

Trouble downloading packages list due to a “Hash sum mismatch” error