Useful CLI tools (bash) for Arch Linux administration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
2.1 KiB

6 years ago
6 years ago
  1. #!/usr/bin/env bash
  2. #
  3. # extract - Extract wide range of various archive types with native tools
  4. #
  5. # Copyright (C) 2021 Pekka Helenius <pekka.helenius@fjordtek.com>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #####################################
  20. if [ -z "$1" ]; then
  21. # display usage if no parameters given
  22. echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
  23. echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
  24. return 1
  25. else
  26. for n in $@
  27. do
  28. if [ -f "$n" ] ; then
  29. case "${n%,}" in
  30. *.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
  31. tar xvf "$n" ;;
  32. *.lzma) unlzma ./"$n" ;;
  33. *.bz2) bunzip2 ./"$n" ;;
  34. *.rar) unrar x -ad ./"$n" ;;
  35. *.gz) gunzip ./"$n" ;;
  36. *.zip) unzip ./"$n" ;;
  37. *.z) uncompress ./"$n" ;;
  38. *.7z|*.arj|*.cab|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.rpm|*.udf|*.wim|*.xar)
  39. 7z x ./"$n" ;;
  40. *.xz) unxz ./"$n" ;;
  41. *.exe) cabextract ./"$n" ;;
  42. *)
  43. echo "extract: '$n' - unknown archive method"
  44. return 1
  45. ;;
  46. esac
  47. else
  48. echo "'$n' - file does not exist"
  49. return 1
  50. fi
  51. done
  52. fi