#!/bin/bash # delete files that were extracted from a tarchive # obviously you want to be very careful with this... # specify 2nd arg as "yes" for it to really do anything tarchive=$1 really=$2 if [ "$tarchive" != "${tarchive%%.tar}" ]; then list=$(tar tvf $tarchive | awk '{print $6}') elif [ "$tarchive" != "${tarchive%%.tbz}" -o \ "$tarchive" != "${tarchive%%tar.bz2}" ]; then list=$(tar tvfj $tarchive | awk '{print $6}') elif [ "$tarchive" != "${tarchive%%tgz}" -o \ "$tarchive" != "${tarchive%%.tar.gz}" ]; then list=$(tar tvfz $tarchive | awk '{print $6}') fi if [ "$really" = "yes" ]; then for file in $list; do if [ -f "$file" ]; then rm -f "$file"; fi done elif [ "$really" = "maybe" ]; then for file in $list; do if [ -f "$file" ]; then echo "$file" ready to delete else echo no such file "$file" fi done else echo files: $list fi