新建存放可执行文件的目录,比如"~/tools/bin”

1
mkdir -p ~/tools/bin

将"~/tools/bin"添加到PATH

编辑~/.bashrc添加

1
export PATH=$PATH:~/tools/bin

执行

1
. ~/.bashrc

在~/tools/bin下新建脚本"unzip.py”

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
import sys
import zipfile

print("Processing File " + sys.argv[1])

file=zipfile.ZipFile(sys.argv[1],"r");
for name in file.namelist():
    print("Extracting " + name)
    utf8name=bytes(name, encoding = "cp437").decode('utf-8')
    print("Extracting " + utf8name)
    pathname = os.path.dirname(utf8name)
    if not os.path.exists(pathname) and pathname!= "":
        os.makedirs(pathname)
    data = file.read(name)
    if not os.path.exists(utf8name):
        fo = open(utf8name, "wb")
        fo.write(data)
        fo.close
file.close()

为unzip.py添加执行权限

1
chmod +x ~/tools/bin/unzip.py

使用

1
unzip.py ***.zip