命令行下操作百度网盘baidupcs

百度网盘命令行操作baidupcs
转载与http://baidunetworkdisk.codeplex.com/
原始连接比较乱,我这里整理了下,有轻微的修改并测试使用,写出发现的问题

一 在ubuntu上安装此命令

1. 安装依赖

apt-get install build-essential libcurl4-openssl-dev libssl-dev

2. 获取源代码

git clone https://github.com/GangZhuo/BaiduPCS.git

3. 编译源代码

cd BaiduPCS
make clean
make
make install #将安装到/usr/local/bin下 这里使用sudo操作

如上安装完毕之后会出现baidupcs这条指令
执行baidupcs help 会出现这条指令的帮助信息
wq3028@M8550S:~/BaiduPCS$ baidupcs help
pcs v0.3.1 (API v1.1.5)baidupcs

Usage: baidupcs command [options] [arg1|arg2…]

Description:
The baidupcs is client of baidu net disk. It supplied many functions,
which can manage baidu net disk on terminal, such as ls, cp, rm,
mv, rename, download, upload, search and so on.
The baidupcs provided AES encryption, which can protected your data.
The baidupcs is open source, and published on MIT.
Please see https://github.com/GangZhuo/baidupcs.

Options:
–context= Specify context.

Commands:
cat Print the file content
cd Change the work directory
copy Copy the file|directory
compare Print the differents between local and net disk
context Print the context
download Download the file
echo Write the text into net disk file
encode Encrypt/decrypt the file
fix Fix file base md5 and scrap
help Print the usage
list List the directory
login Login
logout Logout
meta Print the file|directory meta information
mkdir Make a new directory
move Move the file|directory into other file|directory
pwd Print the current work directory
quota Print the quota
remove Remove the file|directory
rename Rename the file|directory
set Change the context, you can print the context by ‘context’ command
search Search the files in the specify directory
synch Synch between local and net disk. You can ‘compare’ first.
upload Upload the file
version Print the version
who Print the current user
Use ‘baidupcs -h’ to print command usage.
Sample:
baidupcs help
baidupcs help cat
baidupcs cat -h
baidupcs cat /note.txt
baidupcs cd /temp
baidupcs cat /note.txt –context=/home/gang/.pcs_context

二 baidupcs基本操作

1 登录网盘

baidupcs login –username= –password=

登录可能需要输入验证码。目前的处理办法是把验证码图片写入到本地文件,用户打开文件识别验证码。
可通过 ‘baidupcs set –captcha_file= 来指定验证码保存路径,
例如:’baidupcs set –captcha_file=/var/www/xxx.com/captch.gif’将文件保存到网站目录下。
可通过 ‘baidupcs context’ 查看当前的执行上下文。执行上下文包括验证码图片保存路径等其他信息。

示例:
baidupcs login -h 可查看login命令的使用方法
baidupcs login 会提示输入用户名和密码
baidupcs login –username=gang 指定用户名登录
baidupcs login –username=gang –password=123456 指定用户名和密码登录

也可以直接输入baidupcs login 进入交互模式 然后输入账号密码
然后会让你输入验证码,会保存到如下路径的gif中,把他搞出来然后输入进去就登录成功了,可以操作了
The captcha image at /home/wq3028/.pcs/captcha.gif.
Please input the captcha code: 海域一面

2 退出网盘

baidupcs logout

3 查看当前网盘路径

baidupcs pwd 登陆后为/目录
wq3028@M8550S:~$ baidupcs pwd
/

4 查看网盘使用空间

选项:
-e 打印精确的网盘空间
示例:
baidupcs quota
wq3028@M8550S:~ baidupcsquota710.59GB/2.01TBbaidupcsquotaewq3028@M8550S:  baidupcs quota -e
762987615342 Bytes /2210834415616 Bytes

5 查看当前登录用户

baidupcs who
wq3028@M8550S:~$ baidupcs who
wq302821

6 查看当前版本

baidupcs version
wq3028@M8550S:~$ baidupcs version
pcs v0.3.1 (API v1.1.5)baidupcs

三 网盘文件操作

1.列出网盘根目录下的文件或目录

baidupcs list dir
baidupcs ls dir
baidupcs ls
PAGE#1

D Size Modify Date Time File Name

d 0 2014-01-11 21:57:39 /apps
d 0 2018-01-17 15:10:39 /hanwq
d 0 2017-10-16 10:05:02 /lenovo
d 0 2015-11-24 20:46:24 /PPT
d 0 2016-03-17 10:54:34 /Stardew Valley资料
d 0 2017-09-06 14:47:54 /Video Game Show — The Witcher 3- Wild Hunt concert
d 0 2017-04-06 16:05:20 /安装包
d 0 2017-10-19 11:04:48 /给别人的镜像
d 0 2016-07-31 21:35:07 /简历
d 0 2013-12-21 19:16:52 /来自:iPhone
d 0 2016-06-12 16:32:43 /来自:百度相册
d 0 2016-03-31 19:04:53 /嵌入式资料
d 0 2017-04-06 16:08:54 /软件学习资料
d 0 2017-02-23 22:06:45 /树莓派资料
d 0 2016-09-27 20:33:00 /我的资源
d 0 2015-01-25 08:12:05 /相声
d 0 2017-09-14 17:08:22 /新建文件夹
d 0 2017-07-24 14:37:20 /艺术团
d 0 2016-03-31 19:08:00 /音乐


Total: 107.86MB, File Count: 1, Directory Count: 19

Print next page#2 [Y|N]? N

2.切换工作目录

baidupcs cd

示例:
baidupcs cd hanwq //相对路径
baidupcs cd /hanwq //绝对路径

3.创建目录

baidupcs mkdir

示例:
pcs mkdir music //相对路径
pcs mkdir /music/china //绝对路径

4.显示当前网盘的工作目录

baidupcs pwd
示例:
baidupcs pwd
wq3028@M8550S:~ baidupcspwd/wq3028@M8550S:  baidupcs cd hanwq
Work directory changed to /hanwq
wq3028@M8550S:~$ baidupcs pwd
/hanwq

5.删除文件或目录

baidupcs remove
baidupcs rm

6.重命名网盘文件或目录

baidupcs rename
baidupcs ren
注意:是新的文件名字,而不是文件路径。如果需要移动文件到另一个目录,请使用 ‘pcs move’。
示例:
baidupcs rename /data.txt data_20140118.txt

7.复制网盘文件或目录

baidupcs copy
示例:
baidupcs copy data.txt data_20140118.txt

8.移动网盘文件或目录

baidupcs move
baidupcs mv
示例:
baidupcs move /data_20140118.txt /subdir/data.txt
baidupcs move music /my/music

9.直接保存文本到网盘中

baidupcs echo -a
选项:
-a 指定把文本添加到文件末尾,而不是完全替换
示例:
baidupcs echo data.txt “The text that saved by pcs.”

10.搜索文件

baidupcs search -r dir
示例:
baidupcs search note.txt 在当前工作目录搜索 note.txt
baidupcs search /music desc.mp3 在/music目录搜索 desc.mp3
baidupcs search -r note.txt 在当前工作目录递归搜索 note.txt
baidupcs search -r /music desc.mp3 在/music目录递归搜索 desc.mp3

四 上传下载同步

1.下载文件

baidupcs download -f
baidupcs d -f
只能下载文件,如果需要下载目录,请使用 ‘pcs synch -d ’。
选项:
-f 如果本地文件存在的话,强制替换
示例:
baidupcs download /backup/data.20140118.tar.gz ~/download/data.20140118.tar.gz

2.上传文件

baidupcs upload -f
baidupcs u -f
只能上传文件,如果需要上传目录,请使用 ‘pcs synch’ 命令。
示例:
baidupcs upload ~/data.tar.gz /backup/data.20140118.tar.gz

3.同步目录

baidupcs synch -cdenru
baidupcs s -cdenru

同步本地文件和远端文件、本地目录和远端目录。
默认选项是’-cdu’,即上传需要上传的文件、下载需要下载的文件和打印无法确定上传下载的文件。

比较规则:(同’compare’一样)
只通过时间来进行比较。
I) 如果本地和远端都是文件:
a) 本地最后修改时间大于网盘文件上传时间,则认为需要上传;
b) 本地最后修改时间小于网盘文件上传时间,则认为需要下载;
(此处注意:当一个文件上传到网盘后,其网盘时间肯定比本地最后修改时间大。
如果此时执行比较的话,则会认为该文件需要从网盘下载。
下载则没有此问题,因为一个文件下载后,程序会使用
网盘时间来更新本地文件的最后修改时间。)
II) 本地存在,网盘不存在,则认为需要上传
III) 本地不存在,网盘存在,则认为需要下载
IV) 如果一端是文件,另一端是目录,则认为无法确认是上传还是下载。

选项:
-c 只打印出无法确定上传或下载的项。
一般是因为本地是文件,远端是目录,或本地是目录远端是文件
-d 只下载需要下载的文件或目录
-e 只打印相同的文件或目录
-n 只是打印,而不真正的执行上传和下载,等价于’compare’
-r 递归比较其子目录
-u 只上传需要上传的文件或目录

示例:
baidupcs synch music music
baidupcs synch -r ~/music music
baidupcs synch -u music music 只上传需要上传的文件,等价于备份
baidupcs synch -d music music 只下载需要下载的文件,等价于还原
baidupcs synch -du music music 上传需要上传的文件,并且下载需要下载的文件,等价于同步

注意:推荐每次都带上’-c’选项,可以打印出不知道如何处理的文件或目录,防止漏上传或下载。

猜你喜欢

转载自blog.csdn.net/wq3028/article/details/79085862
今日推荐