LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-29-2005, 06:00 PM   #1
tarja
LQ Newbie
 
Registered: Nov 2005
Posts: 8

Rep: Reputation: 0
Bash - listing directories


how can i go thru each user directory and output the file(s) inside them using a for loop?

thanks
 
Old 11-29-2005, 06:23 PM   #2
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Code:
for i in `find . -type d -print`; do ls $i; done
edit: just noticed you said "user directory". Does that mean each directory in the home dir? If so, use "/home" in the find, i.e. "find /home -type..."

Last edited by BrianK; 11-29-2005 at 06:24 PM.
 
Old 11-29-2005, 06:24 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,973
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Why do you think you need a for-loop?

find /home -type d -maxdepth 2



Cheers,
Tink
 
Old 12-03-2005, 12:34 AM   #4
tarja
LQ Newbie
 
Registered: Nov 2005
Posts: 8

Original Poster
Rep: Reputation: 0
thank you for your quick replies and i apologize for my slow one. I have one more question regarding this topic and thats : how can i cat each file it finds so i can see its contents with the code or code(s) listed above?

Thanks.
 
Old 12-03-2005, 12:42 AM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,973
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
find /home -type f -exec cat {} \;

Beware, though: this will cat binarys, too. Which means
that if they have any kinds of archives or office documents
you'll get gibberish, and it may even render your terminal
unusable ...


Cheers,
Tink
 
Old 12-03-2005, 01:18 AM   #6
tarja
LQ Newbie
 
Registered: Nov 2005
Posts: 8

Original Poster
Rep: Reputation: 0
hmm, that doesn't seem to want to work. for my code so far, this is what i have to loop and output my directories :

Code:
for i in `find $d -maxdepth 5 -type d -print`; 
do
{ 
	ls $i | cat -n;

}
done
not sure where to add the code u supplied above to what i have.
 
Old 12-03-2005, 02:15 AM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,973
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Not quite sure what your problem is ...

find /home -type f -print -exec cat -n {} \;
works a treat, does pretty much what you asked for.


Cheers,
Tink
 
Old 12-03-2005, 02:31 PM   #8
tarja
LQ Newbie
 
Registered: Nov 2005
Posts: 8

Original Poster
Rep: Reputation: 0
Thank you, it did work, beautifully. i didn't know i had to remove

Code:
ls $i | cat -n;
anyways, is there a way i can pipe a less command so i can scroll through everything?

Thanks again, really appreciates it.
 
Old 12-03-2005, 04:03 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,973
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Quote:
Originally Posted by tarja
Thank you, it did work, beautifully. i didn't know i had to remove

Code:
ls $i | cat -n;
anyways, is there a way i can pipe a less command so i can scroll through everything?

Thanks again, really appreciates it. :)
Just do exactly that :)

Code:
find /home -type f -print -exec cat -n {} \;|less

Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
putty display loops on listing directories with many files, through expect script vineet.k Linux - General 5 03-13-2007 09:44 AM
Bash Scripts for Dir listing jchristman Linux - General 6 08-26-2004 08:58 AM
recursively listing directories full paths kubicon Linux - Newbie 2 02-22-2004 03:55 PM
proftpd...hangs before listing directories bstew007 Linux - Software 7 12-23-2002 02:57 AM
Display wide listing of files and directories only? northfield Linux - General 3 08-21-2002 06:28 PM


All times are GMT -5. The time now is 07:19 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration