A handy utility (at least for me)
Mario Lobo
mlobo at digiart.art.br
Sat Aug 26 22:45:48 UTC 2006
Hi;
My /usr/ports directory was occuping 24 gigs, of which 20 was just from the
'work' directories !
Removing them one by one was a pain so I wrote this little utility to wipe
them off.
If you find it useful, pass it on. Its not a big deal but thanks for keeping
the credits on it.
Last but not least:
"if any 'member' of your hard disk is caught and killed, the programer will
deny any knowledge of your actions. This program will NOT self-destruct in 5
seconds."
CODE SNIP -------------------------------------------------------
/***************************************************************************
* Copyright (C) 2006 by Mario Lobo
* mlobo at digiart.art.br
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* To compile: gcc -O2 -o dwork dwork.c
*
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char linha[2048],comd[2048];
void clean_it(char *arg);
int main(int argc, char **argv) {
int k = 1;
char *maindir = "/bin/ls -R /usr/ports/", *pad = " | grep /work:" ;
char arq1[100];
printf("\n----------------------------------------------------------------------------------------------------------------\n");
printf("DWORK - /usr/ports/nnn/nnn/'work' directory cleaner. (Mario Lobo -
2006)\n\n");
printf("ex.: dwork (no arguments) -> Deletes 'work' directories
from /usr/ports\n");
printf(" dwork multimedia -> Deletes 'work' directories
from /usr/ports/multimedia\n");
printf(" dwork multimedia audio -> Deletes 'work' directories
from /usr/ports/multimedia AND /usr/ports/audio\n");
printf("----------------------------------------------------------------------------------------------------------------\n\n");
printf("** Working. Please wait....");
if (argc > 1) {
while(k < argc) {
strcpy(comd,maindir);
strcat(comd,argv[k]);
strcat(comd,pad);
strcpy(arq1,"/usr/ports/");
strcat(arq1,argv[k]);
clean_it(arq1);
k++;
}
} else {
strcpy(comd,maindir);
strcat(comd,pad);
clean_it("/usr/ports");
}
printf("\n\n** DONE.\n\n");
}
void clean_it(char *arg) {
char *tmp;
int c = 0;
FILE *fp;
fp = popen(comd,"r");
printf("\n");
while(!feof(fp)) {
memset(linha,0,1024);
fgets(linha,1024,fp);
if (strlen(linha) < 15) continue;
c = 1;
tmp = strchr(linha,'\n');
*tmp = '\0';
tmp = strchr(linha,':');
*tmp = '\0';
printf("\n++ Removing %s....", linha);
strcpy(comd,"/bin/rm -rf ");
strcat(comd,linha);
system(comd);
}
pclose(fp);
if (!c) printf("\n-- NO 'work' directories in %s.",arg);
}
CODE ENDS ------------------------------------------------------
Best wishes,
--
Mario Lobo
http://www.mallavoodoo.com.br
99% rwindows FREE (FBSD not for Pro-Audio.... YET!!!)
More information about the freebsd-hackers
mailing list