From owner-freebsd-hackers@FreeBSD.ORG Sat Aug 26 22:45:47 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C09E416A5A2 for ; Sat, 26 Aug 2006 22:45:47 +0000 (UTC) (envelope-from mlobo@digiart.art.br) Received: from recife.ipad.com.br (recife.ipadnet.com.br [200.249.204.129]) by mx1.FreeBSD.org (Postfix) with ESMTP id 552F544301 for ; Sat, 26 Aug 2006 22:15:40 +0000 (GMT) (envelope-from mlobo@digiart.art.br) Received: from lobo (20132169164.user.veloxzone.com.br [201.32.169.164]) (authenticated bits=0) by recife.ipad.com.br (8.12.8/8.12.8) with ESMTP id k7QMh1OU021054 for ; Sat, 26 Aug 2006 19:43:02 -0300 From: Mario Lobo To: freebsd-hackers@freebsd.org Date: Sat, 26 Aug 2006 19:19:06 -0300 User-Agent: KMail/1.9.3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200608261919.07106.mlobo@digiart.art.br> Subject: A handy utility (at least for me) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Aug 2006 22:45:48 -0000 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@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 #include #include 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!!!)