Welcome to WebmasterWorld Guest from 54.145.58.37

Forum Moderators: bakedjake

Message Too Old, No Replies

Deleting backup files

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 6, 2000
posts:904
votes: 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?

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

Senior Member

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

joined:June 17, 2000
posts:2924
votes: 0


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

New User

10+ Year Member

joined:Oct 16, 2001
posts:24
votes: 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

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 6, 2000
posts:904
votes: 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 :)

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

New User

10+ Year Member

joined:Oct 16, 2001
posts:24
votes: 0


Yes, $n is the nth positional parameter.

Thanks for the welcome.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members