Created
June 28, 2017 16:26
-
-
Save GuiMarthe/098aa73f2faeb46ebc2eb027b4538760 to your computer and use it in GitHub Desktop.
cute extract function I found on reddit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://www.reddit.com/r/linux/comments/1u0d8s/dtrx_a_versatile_tool_to_easily_extract_tar_zip/ | |
| extract () { | |
| if [ -f $1 ] ; then | |
| case $1 in | |
| *.tar.bz2) tar xvjf $1 && cd $(echo $1 | sed 's/.tar.bz2//') ;; | |
| *.tar.gz) tar xvzf $1 && cd $(echo $1 | sed 's/.tar.gz//') ;; | |
| *.bz2) bunzip2 $1 && cd $(echo $1 | sed 's/.bz2//') ;; | |
| *.rar) unrar x $1 && cd $(echo $1 | sed 's/.rar//') ;; | |
| *.gz) gunzip $1 && cd $(echo $1 | sed 's/.gz//') ;; | |
| *.tar) tar xvf $1 && cd $(echo $1 | sed 's/.tar//') ;; | |
| *.tbz2) tar xvjf $1 && cd $(echo $1 | sed 's/.tbz2//') ;; | |
| *.tgz) tar xvzf $1 && cd $(echo $1 | sed 's/.tgz//') ;; | |
| *.zip) unzip $1 && cd $(echo $1 | sed 's/.zip//') ;; | |
| *.Z) uncompress $1 && cd $(echo $1 | sed 's/.Z//') ;; | |
| *.7z) 7z x $1 && cd $(echo $1 | sed 's/.7z//') ;; | |
| *) echo "don't know how to extract '$1'..." ;; | |
| esac | |
| else | |
| echo "'$1' is not a valid file!" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment