On Tue, Jul 29, 2008 at 12:11 PM, आशीष शुक्ल Ashish Shukla
<[EMAIL PROTECTED]> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> In <[EMAIL PROTECTED]>, Anupam Jain wrote:
>>Hi all,
>>
>>Does anyone know of a way to get the maximum directory nesting,
>>starting from the specified base, using standard Linux commands only
>>(no php/perl/python etc.)?
>>
>>e.g. if the directory structure is as follows -
>>d1
>>->d2
>>->->d3
>>->->->d4
>>->d5
>>->->d6
>>
>>I need a shell script which will give me the answer "4" (i.e. depth of
>>the deepest directory - d4).
>
> [EMAIL PROTECTED] ~ % find . -type d -printf '%d\n' |sort -n |tail -1
Thanks for the quick replies Gora and Ashish!
Actually even though I said bash, I am running this on busybox which
does not support -printf for the find command. But I drew enough
inspiration from your solution to come up with -
find -type d | awk -F'/' '{print NF-1 "\n"}' | sort -n | tail -1
Which works just as well :)
-- Anupam
_______________________________________________
ilugd mailinglist -- [email protected]
http://frodo.hserus.net/mailman/listinfo/ilugd
Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi
http://www.mail-archive.com/[email protected]/