No Description
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.

archive 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env sh
  2. #
  3. # pbrisbin 2013 - compress/extract archives by extension.
  4. #
  5. ###
  6. if [ -z "$1" ]; then
  7. printf "usage: archive [ -x ] [ file, ... ]\n" >&2
  8. exit 1
  9. fi
  10. case "$1" in
  11. -x|--extract)
  12. shift
  13. for archive; do
  14. case "$archive" in
  15. *.tbz2|*.tar.bz2) tar xvjf "$archive" ;;
  16. *.tgz|*.tar.gz) tar xvzf "$archive" ;;
  17. *.tar) tar xvf "$archive" ;;
  18. *.gz) gunzip "$archive" ;;
  19. *.bz2) bunzip2 "$archive" ;;
  20. *.zip) unzip "$archive" ;;
  21. *.rar) unrar x "$archive" ;;
  22. *.Z) uncompress "$archive" ;;
  23. *.7z) 7z x "$archive" ;;
  24. *)
  25. printf "%s: unknown extension\n" "$archive" >&2
  26. exit 1
  27. ;;
  28. esac
  29. done
  30. ;;
  31. *)
  32. target="$1"; shift
  33. case "$target" in
  34. *.tbz2|*.tar.bz2) tar cvpjf "$target" "$@" ;;
  35. *.tgz|*.tar.gz) tar cvpzf "$target" "$@" ;;
  36. *.gz) cat "$@" | gzip > "$target" ;;
  37. *.bz2) cat "$@" | bzip2 > "$target" ;;
  38. *.zip) zip -r "$target" "$@" ;;
  39. *) $0 "$target.tar.gz" "$target" "$@" ;;
  40. esac
  41. ;;
  42. esac