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.

37 lines
1.3 KiB

6 years ago
  1. #!/bin/bash
  2. ###########################################################
  3. #Extract wide range of various archive types
  4. if [ -z "$1" ]; then
  5. # display usage if no parameters given
  6. echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
  7. echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
  8. return 1
  9. else
  10. for n in $@
  11. do
  12. if [ -f "$n" ] ; then
  13. case "${n%,}" in
  14. *.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
  15. tar xvf "$n" ;;
  16. *.lzma) unlzma ./"$n" ;;
  17. *.bz2) bunzip2 ./"$n" ;;
  18. *.rar) unrar x -ad ./"$n" ;;
  19. *.gz) gunzip ./"$n" ;;
  20. *.zip) unzip ./"$n" ;;
  21. *.z) uncompress ./"$n" ;;
  22. *.7z|*.arj|*.cab|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.rpm|*.udf|*.wim|*.xar)
  23. 7z x ./"$n" ;;
  24. *.xz) unxz ./"$n" ;;
  25. *.exe) cabextract ./"$n" ;;
  26. *)
  27. echo "extract: '$n' - unknown archive method"
  28. return 1
  29. ;;
  30. esac
  31. else
  32. echo "'$n' - file does not exist"
  33. return 1
  34. fi
  35. done
  36. fi