Last active
May 24, 2023 06:43
-
-
Save hongkongkiwi/ade25ad349c243aa62871be87b13b9cb to your computer and use it in GitHub Desktop.
Simple shell script to count all files (or directories) in current directory, optionally can pass in a pattern for find
This file contains 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/sh -u | |
# Count all files | |
# ./count | |
# Count only mp3 files | |
# ./count "*.mp3" | |
# Count only directories | |
# ./count "" "d" | |
# Count only directories ending with blah | |
# ./count "*blah" "d" | |
PATTERN="${1:-"*"}" | |
COUNT_TYPE="${2:-"f"}" | |
exec find * -maxdepth 1 -type "$COUNT_TYPE" -name "$PATTERN" | wc -l | tr -d ' ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment