extract 627 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env bash
  2. # This script/function will unzip most filetypes automatically
  3. extract () {
  4. if [ -f "$1" ] ; then
  5. case "$1" in
  6. *.tar.bz2) tar xjf "$1" ;;
  7. *.tar.gz) tar xzf "$1" ;;
  8. *.bz2) bunzip2 "$1" ;;
  9. *.rar) unrar e "$1" ;;
  10. *.gz) gunzip "$1" ;;
  11. *.tar) tar xf "$1" ;;
  12. *.tbz2) tar xjf "$1" ;;
  13. *.tgz) tar xzf "$1" ;;
  14. *.zip) unzip "$1" ;;
  15. *.Z) uncompress "$1" ;;
  16. *.7z) 7z x "$1" ;;
  17. *) echo "$1 cannot be extracted via extract()" ;;
  18. esac
  19. else
  20. echo "$1 is not a valid file"
  21. fi
  22. }
  23. # Allow script to be safely sourced
  24. if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
  25. extract "$@"
  26. exit $?
  27. fi