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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List directory structure with files

Status
Not open for further replies.

danno74

IS-IT--Management
Nov 13, 2002
295
0
0
US
Greetings!

I am trying to find a way to list a directory tree with the files that are included in each directory. I foudn a script that will list the directory tree itself, but not list the files in the directories:


I also know that by using ls -Rl I can get just a standard output of the folders with their contents, but i would like to somehow get the script to do this in an easier to read format.

I also came across this, but I don't know how to get it to work. I copied and pasted it into a .sh file and tried to run it, but I cannot get it to run correctly:

I am running Solaris 10.

Thanks for any suggestions or recommendations you can share.

- Dan
 
Code:
find -maxdepth 1 -type d | while read dir; do 
    count=$(find "$dir" -maxdepth 1 -iname \*.jpg | wc -l)
    echo "$dir ; $count"
done

This is fl.sh. I attempt to run it:

./fl.sh

I get:

# ./fl.sh
find: illegal option -- m
find: [-H | -L] path-list predicate-list

I know it doesn't like -maxdepth. I try to put a '.' after find and get the following:

# ./fl.sh
find: bad option -maxdepth
find: [-H | -L] path-list predicate-list
#

And it is at this point I conclude it isn't running correctly, and don't know enough about unix to troubleshoot further, throw my hands in the air and write a post here :)

Thanks for the quick glance.
 
Hi

There is nothing to troubleshoot. Try it with [tt]/usr/xpg4/bin/find[/tt] too, and neither that supports the -maxdepth option, that script is not for your operating system.

Feherke.
 
easier to read format ??? Can you be more specific ...

How about this:

ls -Rp | egrep -v '\/$|\.:'

The "p" argument appends a slash '/' after each dir name, thus allowing the egrep -v to remove these dirs (as well as the current dir '.:' element). Otherwise, these dirs would be recursively listed, and thus would be a distraction - I'm guessing you don't want them to appear twice in your format.
 
Hi

On Linux systems used to be a [tt]tree[/tt] command, which is quite flexible and produces easy to read output. I would give it a try first.

Probably you not have it, so get its source from ftp://mama.indstate.edu/linux/tree/ and try to build it. Its Makefile has Solaris-specific settings too, you just have to uncomment them.

Feherke.
 
Thank you both for the suggestions. We are looking to take an inventory of our campus web tree, to see what is out there in a couple different formats. Just something I need to tweak until our web team has something we like the look of.

Thanks again, I'll look into what you have given me.
 
This gives a nice format:-

find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
 
Have a look at my reply here:
thread822-1414557

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That raises an interesting challenge... I was trying to figure out how to do something like that, but remove the hanging branches, e.g. instead of this:

Code:
.
|____FIC
|____Jazmania
|____actoab
| |____ab123
| | |____ab3423
| | | |____ab12351
| |____ab384
| |____ab435
| |____backup
| | |____ac123
| | | |____ac3423
| | | | |____ac12351
| | |____ac384
| | |____ac435

Display this:

Code:
.
|____FIC
|____Jazmania
|____actoab
  |____ab123
  | |____ab3423
  |   |____ab12351
  |____ab384
  |____ab435
  |____backup
    |____ac123
    | |____ac3423
    |   |____ac12351
    |____ac384
    |____ac435

But I couldn't come up with a straightforward algorithm for it... too much looking forward and backtracking. Any bright ideas?

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top