A handy utility (at least for me)



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@xxxxxxxxxxxxxx
*
* 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!!!)
_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • [PATCH 2.6.18 V6] drivers: add lcd display support
    ... Adds support for the cfag12864b LCD Display as a device driver. ... * GNU General Public License for more details. ... +static void cfag12864b_setbit(unsigned char state, ...
    (Linux-Kernel)
  • [PATCH 2.6.19-rc1 V9] drivers: add LCD support
    ... Adds support for the ks0108 LCD Controller as a device driver. ... +The buffer should be a 128*64 unsigned char array: ... * GNU General Public License for more details. ... +static void cfag12864b_setbit ...
    (Linux-Kernel)
  • [PATCH 2.6.19-rc1 V9] drivers: add LCD support
    ... Adds support for the ks0108 LCD Controller as a device driver. ... +The buffer should be a 128*64 unsigned char array: ... * GNU General Public License for more details. ... +static void cfag12864b_setbit ...
    (Linux-Kernel)
  • Re: Display class
    ... +D: Author: ks0108 LCD Controller driver ... * GNU General Public License for more details. ... +void cfag12864b_set(unsigned char x, unsigned char y) ... +static void cfag12864b_setbit ...
    (Linux-Kernel)
  • Re: gets() is dead
    ... That certainly means I am unable to use fgets() safely, ... char *readstr ... tmp = realloc; ... strcpy(input, buffer); ...
    (comp.lang.c)