Skip to content

Instantly share code, notes, and snippets.

@pmav99
Created January 30, 2017 12:23
Show Gist options
  • Select an option

  • Save pmav99/812ea078cbfc64300a2a4b1991393547 to your computer and use it in GitHub Desktop.

Select an option

Save pmav99/812ea078cbfc64300a2a4b1991393547 to your computer and use it in GitHub Desktop.
Linux extract snippet
#!/bin/bash
# an extract command
x() {
local c e i
(($#)) || return
for i; do
c=''
e=1
if [[ ! -r $i ]]; then
echo "$0: file is unreadable: \`$i'" >&2
continue
fi
case $i in
*.tar) c=(bsdtar xvf);;
*.tar.bz) c=(bsdtar xvf);;
*.t@(gz|lz|xz|b@(2|z?(2))|a@(z|r?(.@(Z|bz?(2)|gz|lzma|xz)))))
c=(bsdtar xvf);;
*.7z) c=(7z x);;
*.Z) c=(uncompress);;
*.bz2) c=(bunzip2);;
*.exe) c=(cabextract);;
*.gz) c=(gunzip);;
*.rar) c=(unrar x);;
*.xz) c=(unxz);;
*.zip) c=(unzip);;
*) echo "$0: unrecognized file extension: \`$i'" >&2
continue;;
esac
command "${c[@]}" "$i"
((e = e || $?))
done
return "$e"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment