Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Listing directories and subdirectories

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-06-2008
karansachdeva karansachdeva is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 27 November 2008, 4:17 AM EST
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Listing directories and subdirectories

How can list the directories and the subdirectories in a folder. It is possible with a single UNIX command.

For example i have a folder named "archive" and another folder named "0808" and then multiple folders are there ...

Can i list all the directories and subdirectories in the folder 0808.

Thanks

Karan
Sponsored Links
    #2  
Old Unix and Linux 10-06-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 
Join Date: Mar 2008
Last Activity: 28 March 2011, 6:41 AM EDT
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks: 0
Thanked 10 Times in 8 Posts

Code:
find archive/0808 -exec ls -ld {} \;

You might also have something like dirtree to list a directory and its subdirectories.
Sponsored Links
    #3  
Old Unix and Linux 10-06-2008
vasanth.vadalur vasanth.vadalur is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 1 March 2013, 8:27 AM EST
Posts: 64
Thanks: 6
Thanked 0 Times in 0 Posts
ls -R
    #4  
Old Unix and Linux 10-06-2008
vasanth.vadalur vasanth.vadalur is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 1 March 2013, 8:27 AM EST
Posts: 64
Thanks: 6
Thanked 0 Times in 0 Posts
Yes it is easy, please use the above command.

vasanth
Sponsored Links
    #5  
Old Unix and Linux 10-06-2008
karansachdeva karansachdeva is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 27 November 2008, 4:17 AM EST
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Era,

This command is showing the file names in the directory as well..

Is it not possible just to list the directory names and the sub directores ..

Thanks

Karan
Sponsored Links
    #6  
Old Unix and Linux 10-06-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 
Join Date: Mar 2008
Last Activity: 28 March 2011, 6:41 AM EDT
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks: 0
Thanked 10 Times in 8 Posts

Code:
find archive/0808 -type d -exec ls -ld {} \;

If you don't want the long-format listing change the -exec ... \; to just -print
Sponsored Links
    #7  
Old Unix and Linux 10-06-2008
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 3 September 2015, 12:43 PM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 4,689
Thanks: 60
Thanked 1,038 Times in 805 Posts
Quote:
Originally Posted by karansachdeva View Post
This command is showing the file names in the directory as well..
Is it not possible just to list the directory names and the sub directores ..
Yes, it is:


Code:
find <startdirectory> -type d -print

prints only the names of the directories, not the files. If you want to output to be "ls -l"-like (more exactly: like "ls -lisa") replace the "-print" with "-ls".

I suggest you read the man page of "find" to learn what other possibilities of changing the output there are.

I hope this helps.

bakunin
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
listing directories and sub directories with time and name options nomadvisuals Shell Programming and Scripting 5 02-22-2012 12:09 AM
Listing subdirectories and files senthil_is Shell Programming and Scripting 1 05-24-2008 07:38 AM
Listing all files in all subdirectories kuciauskas UNIX for Dummies Questions & Answers 3 02-01-2008 04:45 PM
Backup Directories and SubDirectories with log using DOS osramos Windows & DOS: Issues & Discussions 1 11-14-2007 05:10 PM
Display only subdirectories from given directories HAA Shell Programming and Scripting 8 04-25-2007 05:36 AM



All times are GMT -4. The time now is 01:50 AM.