The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Recursive FTP -- here at last. Perderabo Shell Programming and Scripting 52 03-25-2009 12:15 PM
Recursive SFTP MohanTJ Security 1 05-19-2008 12:17 AM
recursive rcp Nicol Shell Programming and Scripting 6 11-06-2003 11:52 AM
Recursive directory listing without listing files psingh UNIX for Dummies Questions & Answers 4 05-10-2002 10:52 AM
Recursive FTP aslamg UNIX for Dummies Questions & Answers 1 03-08-2001 04:27 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-29-2006
bimba17 bimba17 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 1
recursive wc on a directory?

Hi all,
I need to count the number of lines in all the files under a directory (several levels deep). I am feeling extremely dumb, but I don't know how to do that. Needless to say, I am not a shell script wiz... Any advice?

thanks in advance!
  #2 (permalink)  
Old 11-29-2006
Glenn Arndt's Avatar
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
  
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Try this:
Code:
find /topleveldirectory/ -type f -exec wc -l {} \;
  #3 (permalink)  
Old 06-18-2009
cyperfrog cyperfrog is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 1
Total Lines

Hi,

How do I get the total number of lines because when I try this command it just lists them endlessly where I only want one number?

Cheers
  #4 (permalink)  
Old 06-18-2009
achenle achenle is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 76
Quote:
Originally Posted by cyperfrog View Post
Hi,

How do I get the total number of lines because when I try this command it just lists them endlessly where I only want one number?

Cheers
Code:
wc -l `find /dir/name -type f`
Note that those are backticks, and also be aware that if there are too many files you can exceed your shell's argument limitations.
  #5 (permalink)  
Old 06-18-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,532
this is an old thread.
beside exceeding shells argument limitations, you solution does not cater for files with white spaces.
  #6 (permalink)  
Old 06-19-2009
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,175
Code:
find . -type f -print|while read FILENAME
do
      cat "${FILENAME}"
done | wc -l
  #7 (permalink)  
Old 06-19-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,857
Simple and fast:
Code:
find /topleveldirectory/ -type f -exec wc -l {} \; | awk '{total += $1} END{print total}'
No loops, no whitespace problems, no unnecessary cat
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0