If you're like me, and I know I am, you have occasionally untarred into the wrong directory. Oh, the shame! As a metter of fact, I just did this very thing.
This little snippit cleaned out the files. The syntax is:
anti-tar tarfile
Execute it from the base directory you errantly untarred the file into. It will grab the listing of files and dirs from the tar file and remove them from the current directory and subsequent subdirs as needed. It takes advantage of rmdir's severe reluctance to blow away non-empty subdirs.
USE WITH CARE! YMMV!
#!/usr/bin/perl -w
use strict;
use Archive::Tar;
die "Provide the name of the tar file, please!\n"
unless $ARGV[0];
my $tar = Archive::Tar->new();
$tar->read(
$ARGV[0],
0
);
@_ = $tar->list_files();
my @files = sort { $b cmp $a } @_;
foreach ( @files ) {
if ( -d ) {
rmdir
or warn "$_ is not empty (sharred path)\n";
next;
}
unlink;
}