homepage Welcome to WebmasterWorld Guest from 54.196.18.51
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
Deleting backup files
sugarkane




msg:911202
 12:48 pm on Oct 8, 2001 (gmt 0)

I don't know if this scriptlet is of any use to anyone...

Most text editors will automatically create a backup when you edit a file, and pretty soon your directory tree gets filled with files like index.html~ index.html.bak etc. This script crawls recursively through the directory tree deleting common backup filetypes, leaving it nice and clean for uploading. Save somewhere in your path as 'clean' and chmod it to 755

-------------

#!/usr/bin/perl
# usage: clean /home/html
# where /home/html is the root directory of the tree to clean

use File::Find;

$path=shift;

find sub {my $foo=$File::Find::name;
unlink $foo if ($foo=~/~$\.bak$\#$/);
},$path;

-------------

I'm sure there's a neater way to do this in straight shell - any takers?

 

littleman




msg:911203
 12:26 am on Oct 10, 2001 (gmt 0)

Nice little script SK.

richcasto




msg:911204
 3:17 pm on Oct 17, 2001 (gmt 0)

Here's a shell script, but I haven't tested it, so use at your own risk. I recommend reading the manpages on find and xargs if you're not familiar with those commands.

#!/usr/local/bin/bash

cd $1 # if no arg, it will cd to $HOME
(find . -name '*.bak' -print; find . -name '*~' -print) xargs rm -f

sugarkane




msg:911205
 7:40 pm on Oct 17, 2001 (gmt 0)

Nice one, Rich. I didn't know about $1 being the command line parameter. I take it this holds true for $2, $3 etc as well when passing more than one parameter to the script?

Oh, and welcome to wmw BTW :)

richcasto




msg:911206
 9:14 pm on Oct 17, 2001 (gmt 0)

Yes, $n is the nth positional parameter.

Thanks for the welcome.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved