The UNIX and Linux Forums  


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



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 !!

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-29-2006
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
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
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
Registered User
 

Join Date: Jun 2009
Posts: 97
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
Registered User
 

Join Date: Sep 2006
Posts: 2,604
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
Registered User
 

Join Date: Mar 2008
Posts: 1,350

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: 2,596
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
Sponsored Links
Closed Thread

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 Off


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 01: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 11:52 AM
Recursive FTP aslamg UNIX for Dummies Questions & Answers 1 03-08-2001 04:27 AM



All times are GMT -4. The time now is 02:40 PM.


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