Skip to content

Instantly share code, notes, and snippets.

@mattward
Created March 31, 2016 10:11
Show Gist options
  • Save mattward/6bc2c1529937915434ffb196865d789a to your computer and use it in GitHub Desktop.
Save mattward/6bc2c1529937915434ffb196865d789a to your computer and use it in GitHub Desktop.
Count files in the given directories
#!/bin/bash
script_name=`basename $0`
if [[ "$1" == "--help" ]]; then
echo "Usage ${script_name} [subdirectory1 [subdirectory2]...]"
echo "Counts the files in the specified directories, or in all subdirectories if none specified"
exit 1
fi
# Default to all subdirectories, or those specified
if [[ "$1" == "" ]]; then
directories=*
else
directories="$@"
fi
for dir in $directories; do
count=`find $dir -type f | wc -l`
echo "$count $dir"
done | sort -n
@mattward
Copy link
Author

Example output:

MWard@ziggy:mydev$ countf
       1 config
       1 mydev-env
       1 nodejs
       1 ruby
       1 sendgrid.sh
       1 vagrant
       2 c
       3 asciidoc
       3 html
      13 tex
      16 python
      28 jekyll
      40 dotfiles
     211 akka
    1059 java
    2003 eclipse_workspaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment