ex() {
local help="Usage: ex [--help] FILE...
-Extract each FILE according to its extension."
+Extract each FILE according to its extension.
+7z bz2 deb gz iso rar rpm tar xz zip & variations.
+See source for exact file extensions."
if [[ $1 == --help ]]; then
echo "$help"
fi
- local x
+ local x super
for x in "$@"; do
case "$x" in
*.tar.bz2 | *.tbz2 ) tar xvjf "$x" ;;
*.rpm ) rpm2cpio "$x" | cpio --extract --make-directories --verbose ;;
*.tar.xz ) tar Jxvf "$x" ;;
*.iso )
+ if [[ $EUID != 0 ]]; then
+ if [[ $(sudo -v) == Sorry* ]]; then
+ echo error: need superuser priveledge for iso file
+ return 1
+ fi
+ super=sudo
+ fi
local temp_dir=$(mktemp -d)
losetup -f
- s mount -o loop "$x" "$temp_dir"
+ $super mount -o loop "$x" "$temp_dir"
local dir="${x%%.iso}"
mkdir "$dir"
cp -av "$temp_dir"/* "$dir"
- s umount "$temp_dir"
+ $super umount "$temp_dir"
;;
*.r[0-9][0-9]|*.rar ) unrar x "$x" ;;
*) echo "I don't kno how to extract $x";;
ex() {
local help="Usage: ex [--help] FILE...
-Extract each FILE according to its extension."
+Extract each FILE according to its extension.
+7z bz2 deb gz iso rar rpm tar xz zip & variations.
+See source for exact file extensions."
if [[ $1 == --help ]]; then
echo "$help"
fi
- local x
+ local x super
for x in "$@"; do
case "$x" in
*.tar.bz2 | *.tbz2 ) tar xvjf "$x" ;;
*.rpm ) rpm2cpio "$x" | cpio --extract --make-directories --verbose ;;
*.tar.xz ) tar Jxvf "$x" ;;
*.iso )
+ if [[ $EUID != 0 ]]; then
+ if [[ $(sudo -v) == Sorry* ]]; then
+ echo error: need superuser priveledge for iso file
+ return 1
+ fi
+ super=sudo
+ fi
local temp_dir=$(mktemp -d)
losetup -f
- s mount -o loop "$x" "$temp_dir"
+ $super mount -o loop "$x" "$temp_dir"
local dir="${x%%.iso}"
mkdir "$dir"
cp -av "$temp_dir"/* "$dir"
- s umount "$temp_dir"
+ $super umount "$temp_dir"
;;
*.r[0-9][0-9]|*.rar ) unrar x "$x" ;;
*) echo "I don't kno how to extract $x";;