Skip to content

Instantly share code, notes, and snippets.

@RichardBarrell
RichardBarrell / size_t_minus_one.c
Last active February 4, 2017 04:14
Demonstrating that converting an int containing -1 to size_t does the right thing even where sizeof(int) != sizeof(size_t)
#include <stdint.h>
#include <stdio.h>
#include <limits.h>
typedef struct rtunion {
char whatever[8];
} rtunion;
int main (int argc, char **argv) {
(void)argc;
# 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