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!

I need to find all files and sub dir and file and list them to a file

Status
Not open for further replies.

1971240z

Technical User
Jul 24, 2002
20
US
can anyone help me?

I need a script that can read a file that has a list of dirs. Then list out all the files, sub dirs, and files in the sub dirs to a new file. Does anyone know how to do this?

example input file

/opt/netscape
/opt/program1

example output file

/opt/netscape
/opt/netscape/file1
/opt/netscape/file2
/opt/netscape/dir1
/opt/netscape/dir1/file1
/opt/program1
/opt/program1/file1
/opt/program1/dir1
/opt/program1/dir1/dir
/opt/program1/dir1/dir/file
 
A simple korn shell script shall do this job:

cd /opt/netscape
# redirect o/p of following cmd to a file
ls -lR > /path-to/filename
cd /opt/program1
ls -lR >> /path-to/filename
# U can write o/p of second cmd to new file as well

THats it!

Regds,

- Hemant
Networking and Systems Integration Group
Satyam Computer Services Ltd
 
Further to my earlier post:
Hope i am understanding ur problem..
Let me know if u need anything else than this

Regds,

- Hemant
Networking and Systems Integration Group
Satyam Computer Services Ltd
 
Why not just use the file containing the list of directories
as your input, maybe like this:

for DIR in `cat yourfile`
do
find $DIR >> /tmp/newfile
done

or you could change the find to:
find $DIR -ls >> /tmp/newfile

Regards


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top