Skip to content

Instantly share code, notes, and snippets.

@allejo
Created October 30, 2012 01:42
Show Gist options
  • Save allejo/3977827 to your computer and use it in GitHub Desktop.
Save allejo/3977827 to your computer and use it in GitHub Desktop.
Total Number of Lines of a Given File Type in a Folder
#!/bin/bash
if [ -z "$1" ] # Check if no argument was passed
then
echo "No extension specified."
exit
fi
# If someone passes * as an argument it'll pass all the
# files in the directory as arguments, so we just need
# check if another variable is set and we'll know
# whether more than one argument was passed
if [ "$2" ]
then
find . -name '*.*' | xargs wc -l
else
find . -name '*.'$1 | xargs wc -l
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment