The UNIX and Linux Forums
Forum Home
Linux and Unix Man Pages
Search Forums
Search Community Posts
Today's Posts
Quick Links
Man Pages
RedHat Commands
OpenSolaris Commands
Linux Commands
SunOS Commands
FreeBSD Commands
All UNIX Man Pages
All Linux Man Pages
Full Man Repository
Login or Register to Ask a Question and Join Our Community
Search Forums
Show Threads .
Show Posts
Tag Search
Advanced Search
Quick Links
Contact Us
Forum Rules
Today's Posts
FAQ
Pictures & Albums
All Albums
Miscellaneous
What is My IP
Whois
Mark Forums Read
Shell Programming and Scripting
Help!
Tags
shell scripts
,
unix commands
Login to Discuss or Reply to this Discussion in Our Community
Thread Tools
Search this Thread
Top Forums
Shell Programming and Scripting
Help!
#
1
08-13-2008
dwgi32
Registered User
24,
0
Join Date: Nov 2007
Last Activity: 2 April 2010, 2:06 AM EDT
Posts: 24
Thanks Given: 0
Thanked 0 Times in 0 Posts
Help!
Hi,
Need some help with regard unix commands that can count the total number of files in a directory and counting the total number of lines in each file.
Cheers
dwgi32
View Public Profile for dwgi32
Find all posts by dwgi32
#
2
08-13-2008
ynilesh
Registered User
222,
0
Join Date: Oct 2007
Last Activity: 7 April 2009, 7:39 AM EDT
Location: Bangalore, India.
Posts: 222
Thanks Given: 0
Thanked 0 Times in 0 Posts
Use "wc" command
to count number of files in directory.
Code
:
ls -l | grep -v total | wc -l
to count number of lines in file
Code
:
wc -l filename
Note :
Be aware it count blank lines also.
- nilesh
ynilesh
View Public Profile for ynilesh
Find all posts by ynilesh
#
3
08-13-2008
era
Registered User
3,653,
12
Join Date: Mar 2008
Last Activity: 28 March 2011, 6:41 AM EDT
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks Given: 0
Thanked 12 Times in 10 Posts
Actually simply
ls | grep -vc '^total'
would also work.
Simply
wc -l *
will count lines in each file in the current directory, and print a line for each.
You should note that homework questions are not welcome in these forums.
era
View Public Profile for era
Find all posts by era
#
4
08-13-2008
gouthk
Registered User
7,
0
Join Date: Jul 2008
Last Activity: 14 October 2011, 8:42 AM EDT
Posts: 7
Thanks Given: 0
Thanked 0 Times in 0 Posts
use the following command to find all the files in current directory and list the no of lines in each file.
find ./ -xtype f -maxdepth 1 | xargs wc -l
gouthk
View Public Profile for gouthk
Find all posts by gouthk
#
5
08-13-2008
ynilesh
Registered User
222,
0
Join Date: Oct 2007
Last Activity: 7 April 2009, 7:39 AM EDT
Location: Bangalore, India.
Posts: 222
Thanks Given: 0
Thanked 0 Times in 0 Posts
Forget to mention one thing.....
Please keep your subject informative which help us in sorting.
- nilesh
ynilesh
View Public Profile for ynilesh
Find all posts by ynilesh
Login or Register to Ask a Question
Previous Thread
|
Next Thread
Login or Register to Ask a Question
Member Badges and Information Modal
×