Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-18-2008
Registered User
 
Join Date: Nov 2006
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Tree directory structure of Unix to get final node path

Hi,

I want to list all the last directories from mentioned base path.

for eg: If i have a base path say /base/base1/

How can i get the path till last node in tree like directory structure of unix by applying any command.
so that i will get following output.

/base/base1/base2/final1/final2/last
/base/base1/base2/final1/final3/last
/base/base1/base2/final1/last
/base/base1/base2/final1/final4/last
Sponsored Links
    #2  
Old 12-18-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Location: St. Gallen, Switzerland
Posts: 5,873
Thanks: 80
Thanked 372 Times in 351 Posts

Code:
find /base/base1 -type d -name "last" -print

Sponsored Links
    #3  
Old 12-18-2008
Registered User
 
Join Date: Nov 2006
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
In short i want all the possible unique longest paths under base dir
    #4  
Old 12-18-2008
Registered User
 
Join Date: Nov 2006
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Its not necessary the last node is always "last"
Sponsored Links
    #5  
Old 12-18-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Location: St. Gallen, Switzerland
Posts: 5,873
Thanks: 80
Thanked 372 Times in 351 Posts
Did you try it out at least? Or do I misunderstand


Code:
root@isau02:/data/tmp/testfeld> find bla -type d -print
bla
bla/yoyo
bla/yoyo/last
bla/yoyo/last/some
root@isau02:/data/tmp/testfeld> find bla -type d -name last -print
bla/yoyo/last
root@isau02:/data/tmp/testfeld>

Sponsored Links
    #6  
Old 12-18-2008
Registered User
 
Join Date: Nov 2006
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
In the above directory structure mentioned by you I want only "bla/yoyo/last/some" to be printed.

i.e The longest unique path. Here the last node is "some". I hope it clears now.
Sponsored Links
    #7  
Old 12-18-2008
methyl methyl is offline Forum Staff  
Moderator
 
Join Date: Mar 2008
Posts: 6,388
Thanks: 286
Thanked 668 Times in 640 Posts
A directory with no subdirectories contains only two directories "." and "..".


Code:
#!/bin/ksh
find /base/base1/ -type d -print|sort|while read DIR
do
        DIR_COUNT=`ls -la "${DIR}"|grep \^d|wc -l`
        if [ ${DIR_COUNT} -eq 2 ]
        then
                echo "${DIR}"
        fi
done

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
tree structure of the data ThobiasVakayil Shell Programming and Scripting 2 03-27-2008 01:15 AM
Not able to copy the tree node text in HP UX, while easily done in window friendanoop HP-UX 2 02-08-2007 06:52 PM
Not able to copy the tree node text in solaris, while easily done in window friendanoop Solaris 3 02-01-2007 08:37 AM
MV files from one directory structure(multiple level) to other directory structure srmadab UNIX for Advanced & Expert Users 4 09-13-2006 04:01 PM
Unix/Linux Directory Structure gdboling UNIX for Dummies Questions & Answers 2 10-25-2001 11:00 AM



All times are GMT -4. The time now is 05:37 AM.