Thursday, October 26, 2006

undo a tar eXtraction

if you ever accidentaly untar'ed in the wrong place, here is a method for undoing the extraction.
it tries to remove all files and the enclosing directories.

known bugs: filenames with spaces

tar tzf tarfile.tar.gz | sort -r | remove.sh

#!/bin/bash
# remove.sh
# reads from stdin and removes given file or directory
while read a b; do
if [ -d $a ]; then rmdir $a; else rm -f $a; fi
done

No comments: