Created
March 31, 2016 10:11
-
-
Save mattward/6bc2c1529937915434ffb196865d789a to your computer and use it in GitHub Desktop.
Count files in the given directories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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