Created
August 17, 2017 20:26
-
-
Save RichardBarrell/21235b90b7669da91eedebd26049bba0 to your computer and use it in GitHub Desktop.
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 directories which contain only one entry called "index.html" and delete them | |
# this doesn't enforce that the found "index.html" is a file rather than a directory, symlink, socket, device node, etc | |
find . -depth -print0 | \ | |
awk 'BEGIN{RS="\0";ORS="\0";} match($0, /^(.*)[/]([^/]+)$/, A) {prevDir=dir; dir=A[1]; if ((prevDir == $0) && couldDelete) { print($0); } if (prevDir != dir) { couldDelete = 1; } if (A[2] != "index.html") { couldDelete = 0; } }' | \ | |
xargs -0 rm -r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment