ls command to list recursively ONLY subdirectories | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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 !!

ls command to list recursively ONLY subdirectories

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-21-2005
HLee1981 HLee1981 is offline
Registered User
 
Join Date: Mar 2005
Last Activity: 19 April 2013, 10:05 AM EDT
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Question ls command to list recursively ONLY subdirectories


ls -dlRr
I've tried different combinations of the ls command using the above-mentioned options but none of them are giving me the output I am looking for.

Objective: To get a recursive listing of all subdirectories from a particular starting point. For example, if my starting point is directory A, and directory A contains subdirectories B, C, D, and each of the subdirectories contains a combination of directories and files called B1, C1, D1, etc., I want a recursive listing of the subdirectories contained, so the output will be something like
A
./B
./B1
./C1
etc. while excluding the list of the individual files.

I tried doing a search for 'ls' in the forum but didn't see anything within the first two pages of the results that the search pulled.

Help please!

Thanks!

- Hae

--- Edit ---

Nevermind! Found the answer at Recursive directory listing without listing files

Last edited by HLee1981; 11-21-2005 at 06:08 PM..
Sponsored Links
    #2  
Old 11-21-2005
RTM's Avatar
RTM RTM is offline Forum Advisor  
Registered User
 
Join Date: Apr 2002
Last Activity: 17 October 2014, 8:46 PM EDT
Location: On my motorcycle
Posts: 3,093
Thanks: 1
Thanked 32 Times in 9 Posts
find /A -type d -ls
or
find /A -type d -ls |awk '{print $10}'
Sponsored Links
    #3  
Old 11-21-2005
HLee1981 HLee1981 is offline
Registered User
 
Join Date: Mar 2005
Last Activity: 19 April 2013, 10:05 AM EDT
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by RTM
find /A -type d -ls
or
find /A -type d -ls |awk '{print $10}'
RTM, neither of the commands worked using the find/A prefix. The result I get is find: cannot open /A: No such file or directory.

I tried it using a lowercase a after the /.

Thanks.
    #4  
Old 11-21-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
 
Join Date: Sep 2004
Last Activity: 26 July 2012, 3:38 PM EDT
Location: USA
Posts: 512
Thanks: 0
Thanked 2 Times in 2 Posts
what about


Code:
ls -Rl | grep "[a-z]:" | sed 's/://'

Sponsored Links
    #5  
Old 11-21-2005
RTM's Avatar
RTM RTM is offline Forum Advisor  
Registered User
 
Join Date: Apr 2002
Last Activity: 17 October 2014, 8:46 PM EDT
Location: On my motorcycle
Posts: 3,093
Thanks: 1
Thanked 32 Times in 9 Posts
Yea, sorry about that - you probably don't have a /A - but I was more using your example
Quote:
For example, if my starting point is directory A
Sponsored Links
    #6  
Old 05-14-2009
drodecker drodecker is offline
Registered User
 
Join Date: May 2009
Last Activity: 14 May 2009, 2:19 AM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
One line shell command to retrieve subdirectory names

Here is a brute force way to retrieve sub-directories in shell script:
ls -R | grep ":" | sed "s/://"
Any files named with a colon ":" will cause a false positive.
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
How to list all files in dir and sub-dir's recursively along with file size? nmakkena UNIX for Dummies Questions & Answers 3 10-28-2010 09:23 AM
Recursively concatenate files in subdirectories with the same folder name joyce007 UNIX for Advanced & Expert Users 2 11-09-2009 12:41 PM
recursively concatenate files in subdirectories with same folder name joyce007 UNIX for Dummies Questions & Answers 2 11-05-2009 12:41 AM
Recursively go thorough subdirectories and checkout files shajiasalim Shell Programming and Scripting 3 08-13-2008 07:28 AM
List Files Recursively roberthawke UNIX for Dummies Questions & Answers 9 06-24-2002 07:19 PM



All times are GMT -4. The time now is 11:31 PM.