-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract
More file actions
executable file
·44 lines (38 loc) · 1.1 KB
/
Copy pathextract
File metadata and controls
executable file
·44 lines (38 loc) · 1.1 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
37
38
39
40
41
42
43
44
#!/bin/sh
NAME=$(basename $0)
if [[ $NAME == extract ]] ; then
[[ -z $1 ]] && echo "Usage: $NAME <file to extract>" && exit
[[ ! -f $1 ]] && echo "$1 is not a valid file" && exit
echo "Extracting"
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*.lzma) unlzma $1 ;;
*.lzo) lzop -x $1 ;;
*) echo "Unknown file '$1'..." ;;
esac
else
[[ -z $1 ]] && echo "Usage: $NAME <files to compress>" && exit
echo "Compressing"
case $1 in
tbz) tar cjvf $2.tar.bz2 $2 ;;
tgz) tar czvf $2.tar.gz $2 ;;
tar) tar cpvf $2.tar $2 ;;
bz2) bzip2 -c $2 > $2.bz2 ;;
lzma) lzma -c $2 > $2.lzma ;;
gz) gzip -c -9 -n $2 > $2.gz ;;
zip) zip -r $2.zip $2 ;;
7z) 7z a $2.7z $2 ;;
lzo) lzop $2 ;;
*) echo "'$1' cannot be packed via $NAME" ;;
esac
fi