-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextract_archive
executable file
·33 lines (28 loc) · 1.1 KB
/
extract_archive
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
#!/bin/bash
archived_file=$1
# latest_file=$(find $HOME/Downloads/ \( -iname \*.zip -o -iname \*.tar.gz -o -iname \*.tgz -o -iname \*.xz -o -iname \*.tar.bz2 \) -type f -newermt $(date '+%F') -ls | gawk '{ print $11}' | sort -f -i -r | head -1 )
extension="${archived_file##*.}"
#extension2="${archived_file#*.}"
filename="${archived_file%.*}"
filename2=$(basename -- "${filename%.*}")
usage() {
if [[ "$archived_file" == "" ]];then
echo "You are suppose to use: $(basename $0) filename.[zip|tar.gz|tgz|bz2|xz]"
exit 1
fi
}
if [[ "$extension" == "zip" ]];then
$(command -v unzip) "$archived_file" >/dev/null 2>&1
elif [[ "$extension" == "gz" ]];then
$(command -v tar) -xvzf "$archived_file" >/dev/null 2>&1
#elif [[ "$extension2" == "tar.gz" ]];then
# $(command -v tar) xvzf "$archived_file" >/dev/null 2>&1
elif [[ "$extension" == "bz2" ]];then
$(command -v bunzip2) "$archived_file" >/dev/null 2>&1
$(command -v tar) -xvf "$filename" >/dev/null 2>&1
elif [[ "$extension" == "xz" ]];then
$(command -v unxz) "$archived_file" >/dev/null 2>&1
else
echo Archiving has failed
usage
fi