Re:Scripts I wrote that I use all the time
by alberand on Wednesday October 22, 2025 @04:52PM
(#45674999)
My fav script to unpack anything, found a few years ago somewhere
[ Parent
| on HN ]
Re:Scripts I wrote that I use all the time
by juancroldan on Wednesday October 22, 2025 @05:18PM
(#45675265)
That's brilliant. Now I need its compressing counterpart.
Re:Scripts I wrote that I use all the time
by alberand on Thursday October 23, 2025 @11:01AM
(#45682643)
For compression, I have one for .tar.gz. But it's not that popular in my system. I need something a bit easier than 'pack file file file archive.tar.gz'
Re:Scripts I wrote that I use all the time
by rbonvall on Wednesday October 22, 2025 @06:14PM
(#45675843)
I use dtrx, which also ensures that all files are extracted into a folder.
Re:Scripts I wrote that I use all the time
by alanbernstein on Wednesday October 22, 2025 @05:01PM
(#45675099)
`aunpack` does the trick for me.
Re:Scripts I wrote that I use all the time
by gigatexal on Wednesday October 22, 2025 @06:12PM
(#45675820)
Very nice and clean
Re:Scripts I wrote that I use all the time
by YouAreWRONGtoo on Wednesday October 22, 2025 @06:21PM
(#45675905)
Now, add inotify and a systemd user service and you would be getting somewhere. Also packaged versions of that exist already.
So, you created a square wheel, instead of a NASA wheel.
Re:Scripts I wrote that I use all the time
by _whiteCaps_ on Wednesday October 22, 2025 @10:09PM
(#45677409)
`tar xf` autodetects compressed files now. You can replace any of your instances of tar with that.
Re:Scripts I wrote that I use all the time
by soraminazuki on Thursday October 23, 2025 @03:35AM
(#45679233)
Yes, but only bsdtar has support for zip, rar, and 7z.
Re:Scripts I wrote that I use all the time
by alberand on Thursday October 23, 2025 @10:58AM
(#45682609)
Honestly, it doesn't need any updates, it works so great without any pain, I'm just happy with it
Re:Scripts I wrote that I use all the time
by lordgrenville on Thursday October 23, 2025 @02:46PM
(#45685318)
Think this is the source https://justin.abrah.ms/bash/forgotten_friend_3.html
Re:Scripts I wrote that I use all the time
by junkblocker on Thursday October 23, 2025 @11:39PM
(#45690508)
I had found a zsh version somewhere which I've updated a few times over the years though I don't get a chance to use it much. :'D
un () {
unsetopt extendedglob
local old_dirs current_dirs lower do_cd
if [ -z "$1" ]
then
print "Must supply an archive argument."
return 1
fi
if [ -d "$1" ]
then
print "Can't do much with directory arguments."
return 1
fi
if [ ! -e "$1" -a ! -h "$1" ]
then
print "$1 does not exist."
return 1
fi
if [ ! -r "$1" ]
then
print "$1 is not readable."
return 1
fi
do_cd=1
lower="${(L)1}"
old_dirs=(*(N/))
undone=false
if which unar > /dev/null 2>&1 && unar "$1"
then
undone=true
fi
if ! $undone
then
INFO="$(file "$1")"
INFO="${INFO##*: }"
if command grep -a --line-buffered --color=auto -E "Zstandard compressed data" > /dev/null <<< "$INFO"
then
zstd -T0 -d "$1"
elif command grep -a --line-buffered --color=auto -E "bzip2 compressed" > /dev/null <<< "$INFO"
then
bunzip2 -kv "$1"
elif command grep -a --line-buffered --color=auto -E "Zip archive" > /dev/null <<< "$INFO"
then
unzip "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E "RAR archive" > /dev/null
then
unrar e "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E 'xar archive' > /dev/null
then
xar -xvf "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "tar archive" > /dev/null
then
if which gtar > /dev/null 2>&1
then
gtar xvf "$1"
else
tar xvf "$1"
fi
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "LHa" > /dev/null
then
lha e "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "LHa" > /dev/null
then
lha e "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E "compress'd" > /dev/null
then
uncompress -c "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E "xz compressed" > /dev/null
then
unxz -k "$1"
do_cd=0
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E "7-zip" > /dev/null
then
7z x "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E "RPM " > /dev/null
then
if [ "$osname" = "Darwin" ]
then
rpm2cpio "$1" | cpio -i -d --quiet
else
rpm2cpio "$1" | cpio -i --no-absolute-filenames -d --quiet
fi
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E "cpio archive" > /dev/null
then
cpio -i --no-absolute-filenames -d --quiet < "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E "Debian .* package" > /dev/null
then
dpkg-deb -x "$1" .
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i " ar archive" > /dev/null
then
ar x "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "ACE archive" > /dev/null
then
unace e "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "ARJ archive" > /dev/null
then
arj e "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "xar archive" > /dev/null
then
xar -xvf "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "ZOO archive" > /dev/null
then
zoo x "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -Ei "(tnef|Transport Neutral Encapsulation Format)" > /dev/null
then
tnef "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "InstallShield CAB" > /dev/null
then
unshield x "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -Ei "(mail|news)" > /dev/null
then
formail -s munpack < "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "uuencode" > /dev/null
then
uudecode "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "cab" > /dev/null
then
cabextract "$1"
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "PPMD archive" > /dev/null
then
ln -s "$1" . && ppmd d "$1" && rm `basename "$1"`
elif [[ $lower == *.zst ]]
then
zstd -T0 -d "$1"
elif [[ $lower == *.bz2 ]]
then
bunzip2 -kv "$1"
elif [[ $lower == *.zip ]]
then
unzip "$1"
elif [[ $lower == *.jar ]]
then
unzip "$1"
elif [[ $lower == *.xpi ]]
then
unzip "$1"
elif [[ $lower == *.rar ]]
then
unrar e "$1"
elif [[ $lower == *.xar ]]
then
xar -xvf "$1"
elif [[ $lower == *.pkg ]]
then
xar -xvf "$1"
elif [[ $lower == *.tar ]]
then
if which gtar > /dev/null 2>&1
then
gtar xvf "$1"
else
tar xvf "$1"
fi
elif [[ $lower == *.tar.zst || $lower == *.tzst ]]
then
which gtar > /dev/null 2>&1
if [[ $? == 0 ]]
then
gtar -xv -I 'zstd -T0 -v' -f "$1"
elif [[ ${OSTYPE:l} == linux* ]]
then
tar -xv -I 'zstd -T0 -v' -f "$1"
else
zstd -d -v -T0 -c "$1" | tar xvf -
fi
elif [[ $lower == *.tar.gz || $lower == *.tgz ]]
then
which gtar > /dev/null 2>&1
if [[ $? == 0 ]]
then
gtar zxfv "$1"
elif [[ ${OSTYPE:l} == linux* ]]
then
tar zxfv "$1"
else
gunzip -c "$1" | tar xvf -
fi
elif [[ $lower == *.tar.z ]]
then
uncompress -c "$1" | tar xvf -
elif [[ $lower == *.tar.xz || $lower == *.txz ]]
then
which gtar > /dev/null 2>&1
if [[ $? == 0 ]]
then
xzcat "$1" | gtar xvf -
else
xzcat "$1" | tar xvf -
fi
elif echo "$INFO" | command grep -a --line-buffered --color=auto -E 'gzip compressed' > /dev/null || [[ $lower == *.gz ]]
then
if [[ $lower == *.gz ]]
then
gzcat -d "$1" > "${1%.gz}"
else
cat "$1" | gunzip -
fi
do_cd=0
elif [[ $lower == *.tar.bz2 || $lower == *.tbz ]]
then
bunzip2 -kc "$1" | tar xfv -
elif [[ $lower == *.tar.lz4 ]]
then
local mytar
if [[ -n "$(command -v gtar)" ]]
then
mytar=gtar
else
mytar=tar
fi
if [[ -n "$(command -v lz4)" ]]
then
$mytar -xv -I lz4 -f "$1"
elif [[ -n "$(command -v lz4cat)" ]]
then
lz4cat -kd "$1" | $mytar xfv -
else
print "Unknown archive type: $1"
return 1
fi
elif [[ $lower == *.lz4 ]]
then
lz4 -d "$1"
elif [[ $lower == *.epub ]]
then
unzip "$1"
elif [[ $lower == *.lha ]]
then
lha e "$1"
elif which aunpack > /dev/null 2>&1
then
aunpack "$@"
return $?
else
print "Unknown archive type: $1"
return 1
fi
fi
if [[ $do_cd == 1 ]]
then
current_dirs=(*(N/))
for i in {1..${#current_dirs}}
do
if [[ $current_dirs[$i] != "$old_dirs[$i]" ]]
then
cd "$current_dirs[$i]"
ls
break
fi
done
fi
}