tail -f findings.out

« Printing tabular data attractively in Python

Useful ways to list directory contents »

Easily sum matching file line counts

This command will return the number of total lines contained in files ending in .py in the directory it is run in, as well as subdirectories:

1
2
find . -type f -iname *py | xargs -I str wc -l str | \
awk '{SUM += $1} END {print SUM}'

Just change .py to whatever file type you want to get the count.

I wanted to add this as a Bash alias, passing in the filetype as an argument. This would make the whole affair much easier. But when I tried it as an alias, or as a function, I always got 0 back. Running “type” on the alias name returned:

1
2
pylines is aliased to `find . -type f -iname *py | xargs -I str \
wc -l str | awk '{SUM += bell-style} END {print SUM}''

If anyone has any insight into this, please share.

Share and Enjoy:
  • email
  • LinkedIn
  • Slashdot
  • StumbleUpon
  • Technorati
  • Netvibes

Post to Twitter Post to Delicious Post to Digg Post to Reddit

Possibly Related (no promises):

  1. Get useful image information on the command line
  2. Useful ways to list directory contents
  3. Useful Bash functions to determine OS and more
  4. Viewing all users on a Linux system
  5. Checking options with optparse callbacks

Related posts brought to you by Yet Another Related Posts Plugin.

Tags: ,
April 29, 2009 - 7:58 PM
Leave a reply

Subscribe without commenting

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.