homepage Welcome to WebmasterWorld Guest from 54.145.231.20
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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 48 posted 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

WebmasterWorld Senior Member littleman us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 48 posted 12:26 am on Oct 10, 2001 (gmt 0)

Nice little script SK.

richcasto

10+ Year Member



 
Msg#: 48 posted 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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 48 posted 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

10+ Year Member



 
Msg#: 48 posted 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