Created
April 15, 2025 19:57
-
-
Save jasonbeverage/5d3f06e398942a9b5fcacac5d617612d to your computer and use it in GitHub Desktop.
Script to show subdirectories that have at least X files in them. Useful for finding big directories without having to crawl the whole thing.
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 | |
# Usage: ./count_limited_files.sh /base/dir 1000000 | |
BASE_DIR="$1" | |
MAX_FILES="$2" | |
if [[ -z "$BASE_DIR" || -z "$MAX_FILES" ]]; then | |
echo "Usage: $0 /base/dir max_file_count" | |
exit 1 | |
fi | |
if [[ ! -d "$BASE_DIR" ]]; then | |
echo "Error: $BASE_DIR is not a directory" | |
exit 1 | |
fi | |
for subdir in "$BASE_DIR"/*/; do | |
[[ -d "$subdir" ]] || continue # skip non-dirs | |
count=$(find "$subdir" -type f 2>/dev/null | head -n "$MAX_FILES" | wc -l) | |
echo "$subdir: $count files (capped at $MAX_FILES)" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment