Skip to content

Instantly share code, notes, and snippets.

@lencioni
Created August 31, 2017 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lencioni/861fe9f1e4a8006d255ade1a38bcda7c to your computer and use it in GitHub Desktop.
Save lencioni/861fe9f1e4a8006d255ade1a38bcda7c to your computer and use it in GitHub Desktop.
Script to help find nearly empty directories
#!/bin/sh
# Find directories that only contain a single .eslintrc file.
# Adapted from https://superuser.com/a/727070
# Enable double glob to find hidden files
shopt -s dotglob
# Loop through every subdirectory.
# Currently need to tweak this line and run it for every level of directory
# nesting you want to check. TODO: rewrite this so it works recusively better.
for d in **/**/**/**/; do
# Glob a list of the files in the directory.
f=("$d"*)
# If
# 1. there is exactly 1 entry in the directory
# 2. it is a file
# 3. the file name is .eslintrc
if [[ ${#f[@]} -eq 1 && -f "$f" && "${f##*/}" =~ ^.eslintrc$ ]]; then
#echo "$d"
#ls -alh "$d"
git rm -r "$d"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment