Identifying the deepest folder in the tree
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
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.
command-line bash
add a comment |Â
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.
command-line bash
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
add a comment |Â
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.
command-line bash
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
command-line bash
edited Apr 10 at 7:19
muru
130k19273463
130k19273463
asked Apr 10 at 7:02
![](https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=32)
![](https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=32)
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
add a comment |Â
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
add a comment |Â
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)
- looking for directories (
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')"
thanks for this. Appreciate your help in understanding the statement.
â Nish
Apr 10 at 7:33
add a comment |Â
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)
- looking for directories (
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')"
thanks for this. Appreciate your help in understanding the statement.
â Nish
Apr 10 at 7:33
add a comment |Â
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)
- looking for directories (
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')"
thanks for this. Appreciate your help in understanding the statement.
â Nish
Apr 10 at 7:33
add a comment |Â
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)
- looking for directories (
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')"
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)
- looking for directories (
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')"
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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
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