Welcome to WebmasterWorld Guest from 184.73.8.127

Forum Moderators: bakedjake

Message Too Old, No Replies

Deleting backup files

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

WebmasterWorld Senior Member 10+ Year Member



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?

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

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



Nice little script SK.
3:17 pm on Oct 17, 2001 (gmt 0)

10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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 :)

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

10+ Year Member



Yes, $n is the nth positional parameter.

Thanks for the welcome.