Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Directory Structure List - Please help!

Status
Not open for further replies.

billdvldog

Programmer
Sep 6, 2001
43
Our Unix admin recently left. I've been asked to list the directory structure of one of the directories on our Unix server. Is there a way to list only directories and their subdirectories in Unix?

For example, I'd like a list like the following:

dir1
subdir1
subdir11
subdir2
dir2
subdir3
etc, etc...

Thanks in advance!

Bill
 
To take Brian's post on a step further, I have found the following useful (but not perfect) in displaying a directory structure (NB no files are listed).
Eg for /usr :

ls -lR /usr | egrep "^d|^/"

I hope that helps you.

Mike
 
Thanks. I looked at the manpage for ls and tried to run an ls -RdF to recursively get subdirectories, get only directory names (not their contents) and to mark the directory names with a trailing slash (since there doesn't seem to be a way to list only directories, not regular files). It doesn't seem to want to print subdirectories. I'm not sure why. For example, I have a directory called "neto" that has subdirectories "gif" and "envwatch". When I execute "ls -RdF neto" from the command prompt, it simply returns "neto/".

Any ideas? I really appreciate the help!
 
Thanks Mike! I modified your command a bit and it worked like a charm:

ls -lFR /usr | egrep "^d|^/"

Returns results like:

/usr/Summaries
/usr/Summaries/Agreements
/usr/Summaries/Agreements/Dir1
/usr/Summaries/Agreements/Dir2

Thanks again!

Bill
 
see thread822-883828

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top