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.
Possibly Related (no promises):
- Get useful image information on the command line
- Useful Bash functions to determine OS and more
- Viewing all users on a Linux system
Related posts brought to you by Yet Another Related Posts Plugin.







