-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract
More file actions
46 lines (40 loc) · 1.06 KB
/
extract
File metadata and controls
46 lines (40 loc) · 1.06 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
45
46
#!/bin/bash
# Extract any common archive format.
# Usage: extract <file> [file2 ...]
if [ $# -eq 0 ]; then
echo "Usage: extract <file> [file2 ...]"
exit 1
fi
for file in "$@"; do
if [ ! -f "$file" ]; then
echo "Error: '$file' is not a valid file."
continue
fi
echo "Extracting '$file'..."
case "$file" in
*.tar.bz2) tar xjf "$file" ;;
*.tar.gz) tar xzf "$file" ;;
*.tar.xz) tar xJf "$file" ;;
*.tar.zst) tar --zstd -xf "$file" ;;
*.tar) tar xf "$file" ;;
*.tbz2) tar xjf "$file" ;;
*.tgz) tar xzf "$file" ;;
*.bz2) bunzip2 "$file" ;;
*.gz) gunzip "$file" ;;
*.xz) unxz "$file" ;;
*.zst) unzstd "$file" ;;
*.zip) unzip "$file" ;;
*.7z) 7z x "$file" ;;
*.rar) unrar x "$file" ;;
*.Z) uncompress "$file" ;;
*)
echo "Error: Unsupported format for '$file'."
continue
;;
esac
if [ $? -eq 0 ]; then
echo "Done: '$file'"
else
echo "Failed: '$file'"
fi
done