-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract
More file actions
36 lines (33 loc) · 1.26 KB
/
extract
File metadata and controls
36 lines (33 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# A general, all-purpose extraction script.
#
# Default behavior: Extract archive into new directory
# Behavior with `-c` option: Extract contents into current directory
while getopts "hc" o; do case "${o}" in
h) echo -e "Options:\n -c: Extract archive into current directory rather than a new one." && exit ;;
c) dirpref="" && archive=${@:2} ;;
esac done
[ -z ${dirpref+x} ] && dirpref="../" && archive="$@"
if [ -f "$archive" ] ; then
[[ "$dirpref" == "../" ]] && NAME=${archive%.*} && mkdir "$NAME" && cd "$NAME"
case "$archive" in
*.tar.bz2) tar xvjf "$dirpref""$archive" ;;
*.tar.gz) tar xvzf "$dirpref""$archive" ;;
*.tar.xz) tar xvJf "$dirpref""$archive" ;;
*.lzma) unlzma "$dirpref""$archive" ;;
*.bz2) bunzip2 "$dirpref""$archive" ;;
*.rar) unrar x -ad "$dirpref""$archive" ;;
*.gz) gunzip "$dirpref""$archive" ;;
*.tar) tar xvf "$dirpref""$archive" ;;
*.tbz2) tar xvjf "$dirpref""$archive" ;;
*.tgz) tar xvzf "$dirpref""$archive" ;;
*.zip) unzip "$dirpref""$archive" ;;
*.Z) uncompress "$dirpref""$archive" ;;
*.7z) 7z x "$dirpref""$archive" ;;
*.xz) unxz "$dirpref""$archive" ;;
*.exe) cabextract "$dirpref""$archive" ;;
*) echo "extract: '$archive' - unknown archive method" ;;
esac
else
echo "File \"$archive\" not found."
fi