ziming-liu
9/29/2019 - 7:52 AM

命令行linux Ubuntu 使用Google drive

 在Google Drive里面有个很大文件需要下载,在网页上下载时候,因为走的代理,速度很慢。所以就想着能不能先在服务器上下载好,然后提供FTP或者其他方式下载到本地。通过查询资料,发现可以通过gdrive来完成这个操作。

一.安装gdrive
    1.登录服务器,下载gdrive到服务器上:

wget -O gdrive https://sites.google.com/site/wun913/Home/gdrive-linux-x64
    2.移动 gdrive 到 /usr/bin 下:

mv gdrive /usr/bin/gdrive
    3.添加执行权限:

chmod +x /usr/bin/gdrive
 

二.授权
    1.gdrive about 获取验证链接:

[root@server1 drive]# gdrive about
Authentication needed
Go to the following url in your browser:
https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=367116221053-7n0vf5akeru7on6o2fjinrecpdoe99eg.apps.googleusercontent.com&redirect_uri=urn%...2Fwww.googleapis.com%2Fauth%2Fdrive&state=state

Enter verification code:
    2.把回显的链接地址拷贝出来,贴到浏览器中:



    3.把浏览器中的代码,拷贝到刚才的命令行下,敲回车:

Enter verification code: 4/WQBY4me6PvLf5vepIgef_jo12T7o1VHq7b17pLBXq6y7Fhidl_eDPe0
User: jacktager, xiaotang199508@gmail.com
Used: 10.5 MB
Free: 16.1 GB
Total: 16.1 GB
Max upload size: 5.2 TB
    当回显上面的云盘大体内容时,说明已经配置好了,下面就能开始上传下载操作了。

 

三.gdrive常用命令
    1.列出Google Drive根目录下文件、文件夹:

    gdrive list

[root@server1 drive]# gdrive list
Id                                  Name   Type   Size   Created
14eEn7a551cNxxxxd_jdZXSvuIN9EXKcA   idea   dir           2018-03-15 02:01:23
    2.下载Google Drive根目录下文件到本地(xxxx为文件名)

    gdrive download xxxx

    3.下载Google Drive根目录下文件夹到本地(xxx为文件夹名)

    gdrive download xxx

    4.把本地文件上传到Google Drive根目录下(xxxx为文件名)

    gdrive upload xxxx

[root@server1 drive]# gdrive upload xxx.sh
Uploading xxx.sh
Uploaded 1FYUbFZqtWxxx2n4qJ_Trz9cJhzu4uYik at 10.6 KB/s, total 13.7 KB
    5.在Google Drive根目录下创建文件夹(xxx为文件夹名)

    gdrive mkdir xx

 

    基本操作就是这些了。通过gdrive,在Linux上使用很方便。另外,还可以通过脚本,自动备份服务器数据通过gdrive同步到Google Drive上。