LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-09-2007, 02:35 PM   #1
haiders
Member
 
Registered: Sep 2006
Posts: 62

Rep: Reputation: 15
List all files in multiple directories


So I have one directory that has files and directories in it and those directories have files and directories in them. I need to list all *files* in D1 and the files in all subsequent directories. Then eventually execute a command to all the files. How do I do that?
OS: RH Enterprise

|--D2
D1 ---
|--D3


Thanks!
 
Old 05-09-2007, 02:41 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
To list files in sub-directories, use ls -R
 
Old 05-09-2007, 03:34 PM   #3
haiders
Member
 
Registered: Sep 2006
Posts: 62

Original Poster
Rep: Reputation: 15
Hey Pixellany,
Thanks for the quick reply. The problem is that -R lists stuff I don't want as well(directory names). So the output has to be directed to a file with *only* the file names and nothing else.
 
Old 05-09-2007, 03:50 PM   #4
0.o
Member
 
Registered: May 2004
Location: Raleigh, NC
Distribution: Debian, Solaris, HP-UX, AIX
Posts: 208

Rep: Reputation: 35
Use find . -type f ... > ... in the upper most directory.
 
Old 05-10-2007, 08:58 AM   #5
haiders
Member
 
Registered: Sep 2006
Posts: 62

Original Poster
Rep: Reputation: 15
Thanks O.o. That works:
Code:
find . -type f | while read name; do blahblah $name; done
BTW,
know any links for basic understanding of "for" "do" statements/loops?
 
Old 05-10-2007, 09:06 AM   #6
0.o
Member
 
Registered: May 2004
Location: Raleigh, NC
Distribution: Debian, Solaris, HP-UX, AIX
Posts: 208

Rep: Reputation: 35
Quote:
Originally Posted by haiders
Thanks O.o. That works:
Code:
find . -type f | while read name; do blahblah $name; done

You don't even need all of the 'extra' stuff there. You can simply use:

find . -type f > fileList

Last edited by 0.o; 05-10-2007 at 09:30 AM.
 
Old 05-10-2007, 12:05 PM   #7
haiders
Member
 
Registered: Sep 2006
Posts: 62

Original Poster
Rep: Reputation: 15
Yes that would direct the output to file, but I need to execute a command ie., echo files so I would put that in place of "blahblah".
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy files from multiple directories into one directory MadRabbit Linux - Newbie 8 02-07-2014 07:56 PM
Change text in multiple files in multiple directories vivo2341 Linux - General 5 11-27-2006 08:16 PM
Getting a list of directories with certain files inside... Banacek Linux - Newbie 7 11-27-2006 05:43 PM
List all files and recursively open directories. unreal128 Linux - General 2 07-16-2005 02:06 PM
Help I need help tarring multiple files in multiple directories VisionZ Linux - Newbie 28 03-25-2004 05:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration