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

Listing files with their location information 1

Status
Not open for further replies.

globos

Programmer
Nov 8, 2000
260
FR
Hi,

I would like to list the files of a directory recursively.
I want the output format to be like this example (listing current directory) :

foo.hh
foo.cpp
sub-dir1/stuff.hh
sub-dir1/other-stuff.hh
sub-dir1/sub-dir11/ooo.hh
sub-dir2/bar.hh
sub-dir2/other-bar.hh

One file per line, and prefixed with the relative directory.

I tried with "ls -1 -R" but I can't get it to work as I want (I can't prefix with the directory info).

Any ideas with other tools maybe?

Thanks for help.

--
Globos
 
Not quite the format but you can have a play

#!/bin/sh

# dtree: prints a directory tree from the current directory downwards
# or specify a directory from which to print

# e.g. dtree
# e.g. dtree mydir

# Create variable equal to selected directory (or current if none specified)
dir=${1-.}

# Change to the appropriate directory
(cd $dir; pwd)

find $dir -type d -print | sort -f | sed -e "
s:^$1::
/^$/d
/^\.$/d
s:[^/]*/\([^/]*\)$:|-----\1:
s:[^/]*/:| :g"


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."
 
find * -type f

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi,

The easiest way to do this is:

ls -Rx

Hope this helps!

-Joe
 
> ls -Rx

This does not output to the expected format. But I'm using 'ls' with Cygwin, so it maybe have a different behaviour.

--
Globos
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top