请教如何将tar.gz和tar.bz2的提取和创建alias成一个命令
- 0次
- 2021-07-20 00:40:48
- idczone
请教该如何将tar.gz和tar.bz2的提取和创建alias成一个命令,比如:
解压和压缩tar.gz文件
tg -x test.tar.gz
tg -c test.tar.gz dir_test
解压和压缩tar.bz2文件
tb -x test.tar.bz2
tb -c test.tar.bz2 dir_test
这样的alias可以实现吗?求教!
https://github.com/paulirish/dotfiles/blob/master/.functions#L105
zsh 对alias 有更多的支持
其实不用 alias 也行啊
自己用 shell script 写出想要的功能来,丢到 PATH 里不就行了~~
apt-get install atool
apack test.{tar.gz,zip,xz,anything} dir
aunpack test.*
现代的 tar 直接支持自动解压 gnuzip 和 bzip2 格式的 tar包:
tar xf file.tar.bz2
tar xf file.tar.gz
都是可以直接解压成最终的目录/文件的。
解压会自动识别。创建的话需要手动指定。
alias的话也很简单,比如把
tar czf file.tgz dir
简化成
tg c file.tgz dir
可以写
alias tg='tar zf'
Extract archives - use: extract
Credits to http://dotfiles.org/~pseup/.bashrc
function extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $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 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
谢谢!请问如何将该extract函数改成一个正常打包和提取的函数:
提取出文件: extract -x 或者 extract x
打包成文件:extract -c 或者 extract c
BTW,我是linux新手,刚接触shell,多谢各位的帮助!