Skip to content

Instantly share code, notes, and snippets.

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 RichardBarrell/21235b90b7669da91eedebd26049bba0 to your computer and use it in GitHub Desktop.
Save RichardBarrell/21235b90b7669da91eedebd26049bba0 to your computer and use it in GitHub Desktop.
# 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