Created
April 8, 2011 15:36
-
-
Save spudtrooper/910119 to your computer and use it in GitHub Desktop.
If you ever untar a tarball that doesn't contain a directory of files, instead a bunch of files, and you want them all in one directory, this will remove the files extracted from that tarball that were extracted.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Removes the files that were extracted locally from a tar file. This | |
# can be used when a tarball doesn't contain a directory of files and | |
# extracts a bunch of files into the pwd. | |
# | |
# Example: | |
# | |
# % undotar file.tar | |
# % undotar file.tar.gz | |
# % undotar file.jar | |
# % undotar file.zip | |
# % undotar file.bzip2 | |
# | |
function remove_files_from_tar { | |
file=$1 | |
shift | |
case $file in | |
*.tar.gz) | |
cmd="tar tvfz" | |
;; | |
*.tar) | |
cmd="tar tvf" | |
;; | |
*.jar) | |
cmd="jar tvf" | |
;; | |
*.zip) | |
cmd="unzip -t" | |
;; | |
*.bzip2) | |
cmd="bunzip2 -t" | |
;; | |
*) | |
echo "Don't know how to handle $f" | |
return | |
;; | |
esac | |
all=`$cmd $f | awk '{print $NF}' | xargs` | |
for f in $all; do | |
rm -rf $f | |
done | |
} | |
for f in "$@"; do | |
remove_files_from_tar $f | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment