Banner of

My Archive extractor

Category: Linux

Date: December 2022
Views: 986

My personal archive extractor. it's a bash script that simply creates a directory and extract the archive file in int and it supports most of the archive filetypes:



err() {
    printf >&2 "$SCRIPTNAME: $*\n"
    exit 1

file="$(readlink -f "$file")"
mkdir "$file-extDir" 2>/dev/null
case "$file" in
	*.tar.bz2)   tar -xjf        "$file"  -C "$dir"    ;;
	*.tar.gz)    tar -xzf        "$file"  -C "$dir"    ;;
	*.tar.lz)    tar --lzip -xvf "$file"  -C "$dir"    ;;
	*.bz2)       bunzip2         "$file"               ;;
	*.rar)       unrar x         "$file"               ;;
	*.gz)        gunzip          "$file"               ;;
	*.tar)       tar xf          "$file"  -C "$dir"    ;;
	*.tbz2)      tar xjf         "$file"  -C "$dir"    ;;
	*.tgz)       tar xzf         "$file"  -C "$dir"    ;;
	*.zip)       unzip           "$file"  -d "$dir"    ;;
	*.Z)         uncompress      "$file"               ;;
	*.7z)        7z x            "$file"  -o"$dir"    ;;
	*.iso)       7z x            "$file"  -o"$dir"    ;;
	*)           echo "'$file' cannot be extracted by $SCRIPTNAME" ;;

you can make an alias for it in your .bashrc or .zshrc files like so

alias x='/home/mosaid/path/to/'

it works great with ranger file manager. all you have to do is add the following line to ~/.config/ranger/rc.conf

map xx  shell ${HOME}/path/to/ %s


Previous Article Next Article

0 Comments, latest

No comments.