Skip to content

Instantly share code, notes, and snippets.

@amandabee
Created June 21, 2012 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amandabee/2967545 to your computer and use it in GitHub Desktop.
Save amandabee/2967545 to your computer and use it in GitHub Desktop.
First stab at finding directories with a lot of files in them.
#!/bin/bash
## If your first variable is a path to a directory that exists, we'll search
## there instead of wherever you are.
## If you set a second variable that is a number, we'll use that as the cap.
if [[ $2 = *[[:digit:]]* ]]; then
CAP=$2
else
CAP=600
fi
#Separate at line breaks, not spaces.
IFS=$'\n'
## this could/should definitely be more elegant. If you give a path I assume
## it is relative to your current working directory.
if [ "$1" == "" ]; then
RUNDIR=$(pwd)
else
RUNDIR=$(pwd)/$1
fi
if [ ! -d $RUNDIR ]; then
echo "Sorry:" $RUNDIR "is not a directory."
else
echo "Looking for dirs with more than" $CAP "files in" $RUNDIR":"
# Find all the directories.
for FOLDER in $( find "$RUNDIR" -maxdepth 4 -type d)
do
for COUNT in $( find "$FOLDER" | wc -l)
do
if [ "$COUNT" -gt "$CAP" ]; then
echo $FOLDER $COUNT
fi
done
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment