Skip to content

Instantly share code, notes, and snippets.

@buzztaiki
Forked from sasagon/tarx.sh
Created February 14, 2012 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buzztaiki/1824220 to your computer and use it in GitHub Desktop.
Save buzztaiki/1824220 to your computer and use it in GitHub Desktop.
中身が単一ディレクトリになってないアーカイブを展開するときに、適当なディレクトリを作ってからその中に展開するshell script
#!/bin/bash --
for F in $@ ; do
if [ $(tar tf $F | grep -o '^[^/]*/' | sort | uniq | wc -l) -eq 1 ]; then
tar xvf $F
else
D=$F
for x in .tgz .tbz .txz .tar.gz .tar.bz2 .tar.xz; do
D=$(basename "$D" $x)
done
mkdir $D && tar xvf $F -C $D
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment