Created
November 26, 2009 14:31
-
-
Save d0k/243488 to your computer and use it in GitHub Desktop.
find . -name '*...*' -delete
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
#include <stdio.h> | |
#include <string.h> | |
#include <dirent.h> | |
#include <unistd.h> | |
int main(int argc, char *argv[]) { | |
DIR *dir; | |
unsigned long count = 0, unlinked = 0; | |
struct dirent *ent; | |
int ret; | |
if (argc != 3) { | |
fprintf(stderr, | |
"Usage:\n" | |
"\t %s [directory] [needle]\n\n" | |
"example: %s ~/Library/Caches/Metadata/Safari/History/ google\n" | |
"\t removes all URLs containing google from the history cache\n", | |
argv[0], argv[0]); | |
return 1; | |
} | |
ret = chdir(argv[1]); | |
dir = opendir("."); | |
if (ret != 0 || !dir) { | |
perror(argv[1]); | |
return 1; | |
} | |
while ((ent = readdir(dir))) { | |
if (strstr(ent->d_name, argv[2])) { | |
if (unlink(ent->d_name) == 0) | |
unlinked++; | |
else | |
perror(ent->d_name); | |
} | |
count++; | |
} | |
closedir(dir); | |
fprintf(stderr, "Old count:\t%lu files\n", count); | |
fprintf(stderr, "New count:\t%lu files\n", count-unlinked); | |
fprintf(stderr, "Delta:\t\t-%lu\n", unlinked); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment