LinuxQuestions.org
Review your favorite Linux distribution.
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 01-09-2013, 02:06 AM   #1
chuppi
LQ Newbie
 
Registered: Jan 2013
Location: bengaluru
Posts: 3

Rep: Reputation: Disabled
Post count total number of lines in a directory


hi all,

I need a shell script that should print total number of lines in a directory
E.g:- if i have directory(mydir)and that directory contains some files of .c & .h and some other directory(sample)that also have some files.

script should print number of lines of that directory and also sub folders & its files.the output should shows only number of lines(i.e 13245 lines in mydir)
 
Old 01-09-2013, 02:18 AM   #2
ruario
Senior Member
 
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 2,187

Rep: Reputation: 1183Reputation: 1183Reputation: 1183Reputation: 1183Reputation: 1183Reputation: 1183Reputation: 1183Reputation: 1183Reputation: 1183
Read 'man find' and 'man wc' and you will see how to do it yourself.
 
Old 01-09-2013, 04:00 AM   #3
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,415

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Code:
# ls | xargs wc -l
maybe this could help you.
 
Old 01-09-2013, 11:00 AM   #4
Habitual
LQ Addict
 
Registered: Jan 2011
Posts: 7,971
Blog Entries: 11

Rep: Reputation: 2167Reputation: 2167Reputation: 2167Reputation: 2167Reputation: 2167Reputation: 2167Reputation: 2167Reputation: 2167Reputation: 2167Reputation: 2167Reputation: 2167
Quote:
...I need a shell script that should print total number of lines in a directory ...
s/lines/files
 
Old 01-09-2013, 01:30 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Is a subdirectory a 'line'? What about '.' and '..'?
Do you really mean something more like 'I want a recursive count of all files in a directory tree'?

--- rod.
 
  


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
Rename pdf files after their directory name and acoording to their total number IlIl7 Linux - Newbie 3 07-06-2012 04:09 PM
bash script to count number of lines with a specific property7 hhamid Programming 10 08-13-2010 01:35 AM
How to count total number of packages in entire Debian Distribution kushalkoolwal Debian 7 12-17-2008 01:37 PM
Count the number of files in a directory and sub-directories within that directory soumyajit.haldar Linux - Software 4 03-20-2007 06:22 AM
count total number of lines in several files xushi Programming 5 11-12-2005 04:42 PM


All times are GMT -5. The time now is 05:36 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration