Last active
August 18, 2023 02:18
-
-
Save ryanshoover/5aabecb03a193ac9625c73134e3b2975 to your computer and use it in GitHub Desktop.
Flag directories with > 30,000 files
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
find /path/to/starting/directory -mindepth 1 -type d -exec bash -c 'echo -n "{}: "; find "{}" -maxdepth 1 -type f | wc -l' \; |
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-files.sh <directory> | |
# Function to count files in a directory | |
count_files() { | |
local dir="$1" | |
local num_files=$(find "$dir" -type f | wc -l) | |
if [ $num_files -gt 30000 ]; then | |
echo "$dir: $num_files" | |
fi | |
} | |
# Function to recursively count files in directories | |
recursive_count_files() { | |
local start_dir="$1" | |
if [ -d "$start_dir" ]; then | |
count_files "$start_dir" | |
for d in "$start_dir"/*; do | |
if [ -d "$d" ]; then | |
recursive_count_files "$d" | |
fi | |
done | |
fi | |
} | |
# Usage: ./count_files_recursive.sh /path/to/start/directory | |
# Check if an argument is provided | |
if [ $# -ne 1 ]; then | |
echo "Usage: $0 /path/to/start/directory" | |
exit 1 | |
fi | |
start_directory="$1" | |
recursive_count_files "$start_directory" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, Ryan!