Created
August 31, 2017 17:10
-
-
Save lencioni/861fe9f1e4a8006d255ade1a38bcda7c to your computer and use it in GitHub Desktop.
Script to help find nearly empty directories
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 | |
# 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