
In the context of Linux server operation and development, the automated management of Baidu Cloud files often faces two major challenges: the official client lacks Linux support, and the web interface is difficult to integrate into script workflows.This article will unlock a graphical interface-free cloud storage operation solution using the command line tool bypy—from environment setup, authorization management to batch transfer, helping you build an efficient file pipeline for embedded automation tasks, particularly suitable for enterprise-level needs such as remote server backups and CI/CD material synchronization.Preparation: Install Necessary ToolsTo use the bypy tool to download files from Baidu Cloud on a Linux system, you need to have Python installed, as bypy is a Baidu Cloud client tool developed in Python. If your system does not have Python installed, you can install it via the system package manager (such as apt, yum, etc.).Next, you need to install two key Python libraries: requests and bypy. The requests library is a very popular HTTP library used for sending HTTP requests, and the bypy tool relies on it for interaction with Baidu Cloud. The bypy library is the core tool for performing file operations on Baidu Cloud.The commands to install these two libraries are as follows:pip install requests -i https://pypi.doubanio.com/simplepip install bypy -i https://pypi.doubanio.com/simpleHere, the -i parameter specifies the installation source as https://pypi.doubanio.com/simple, which is Douban’s PyPI mirror. PyPI (Python Package Index) is the official software package repository for Python, where developers worldwide upload their libraries.However, due to network issues, downloading directly from the official source may be slow, and using a domestic mirror can significantly speed up the download. In addition to Douban, common domestic mirror sources include Tsinghua University’s mirror https://pypi.tuna.tsinghua.edu.cn/simple and Alibaba Cloud’s mirror http://mirrors.aliyun.com/pypi/simple/, which you can choose based on your actual situation.Create Sync Directory and Authorize AccountAfter installing bypy, the next step is to create a local directory for syncing files from Baidu Cloud. This directory can be located according to your needs and system storage planning. For example, we can create a directory named baidupan under the /share directory specifically for storing files downloaded from Baidu Cloud:mkdir /share/baidupancd /share/baidupanmkdir is short for “make directory” and is used to create a new directory.cd is short for “change directory” and is used to switch the current working directory. After executing the above commands, the current working directory will be switched to /share/baidupan.Next, you need to authorize bypy to access your Baidu Cloud account. Execute the following command in the terminal:bypy infoAfter executing this command, the terminal will output a URL link, similar to https://openapi.baidu.com/oauth/2.0/authorize?client_id=xxxx&response_type=code&redirect_uri=oob&scope=basic+netdisk. This link is the authorization link for Baidu Cloud.
Open your browser, paste this link into the address bar, and visit it. The browser will redirect to the Baidu Cloud login page. Log in with your Baidu account, and after a successful login, you will see an authorization page asking if you allow this application to access your Baidu Cloud. Click the “Agree to Authorize” button, and Baidu Cloud will generate an authorization code.Return to the terminal, paste the obtained authorization code into the terminal, and press Enter. bypy will use this authorization code to interact with Baidu Cloud and complete the authorization process. After successful authorization, you will see some information about your Baidu Cloud account in the terminal, such as total capacity, used capacity, etc. This indicates that bypy has successfully connected to your Baidu Cloud account and can perform subsequent file operations.File Download and Upload Practice(1) Get File ListOnce bypy is successfully authorized and connected to your Baidu Cloud account, you can perform file operations. First, let’s see how to get the file list on Baidu Cloud. Execute the bypy list command in the terminal, which will list all files and folders in the My Application Data /bypy directory on Baidu Cloud.For example, if you have some project documents and images stored in the My Application Data /bypy directory on Baidu Cloud, executing the bypy list command will display the names, sizes, modification times, and other information of these files and folders in a list format, allowing you to clearly see the contents in the cloud storage. This is like opening a folder and seeing a list of all the files inside, making it easy to confirm which specific files you need to download or upload.(2) Download FilesIf you find the file you need to download in the file list, you can use the bypy downdir command to download it. If you want to download all files in the My Application Data /bypy directory, you can execute:bypy downdir -vThe -v parameter is optional and indicates “verbose” mode. By adding this parameter, the download process will display the download progress, the number of bytes downloaded, the estimated remaining time, and other information, allowing you to understand the download progress clearly. For example, when downloading a large compressed file, you can see in real-time how much has been downloaded and how much longer it will take to complete.If you only want to download a specific file, suppose you want to download a file named example.txt, you can execute:bypy downdir -v example.txtIn this way, the example.txt file will be downloaded to the current working directory (i.e., the directory where you executed the command). Note that if a file with the same name already exists in the current directory, bypy may overwrite the original file, so it’s best to confirm whether you need to back up the original file before downloading.(3) Upload FilesUploading files to Baidu Cloud is also straightforward, using the bypy upload command. Suppose you have a local file report.docx that you want to upload to the My Application Data /bypy directory on Baidu Cloud. Switch to the directory where report.docx is located in the terminal, and then execute:bypy upload -v report.docxAgain, the -v parameter is used to display upload progress and other detailed information. After the upload is complete, you can log in to Baidu Cloud and find the recently uploaded report.docx file in the My Application Data /bypy directory. If you want to upload an entire folder, bypy also provides the corresponding functionality, but the command will be slightly different; we will not elaborate on that here. Interested readers can refer to the official bypy documentation for exploration.Secure Logout: Revoke AuthorizationWhen you have completed downloading, uploading, and other operations with Baidu Cloud files and no longer need bypy to maintain an authorized connection with Baidu Cloud, or if you want to reauthorize on another device, or if you are concerned about account security, you can use the bypy -c command to revoke authorization. After executing this command, bypy will delete the locally stored authorization token file and disconnect from your Baidu Cloud account.This is similar to logging out of your account on a shared computer after using it, so that others cannot operate in your name, effectively protecting your account security. If you need to use bypy to access Baidu Cloud again later, you will need to execute the bypy info command to obtain the authorization code and reauthorize. Developing the habit of revoking authorization in a timely manner can reduce the risk of account theft, especially when operating Baidu Cloud in public environments or on temporary devices.Summary and ExpansionThrough the above steps, we have detailed how to use the bypy tool to operate Baidu Cloud via the command line in a Linux system, achieving file downloads, uploads, and management. This method provides an efficient and convenient file management approach for system administrators, developers, and users who need to interact with Baidu Cloud in a Linux environment. It avoids the cumbersome graphical interface operations, especially suitable for file transfer and backup tasks on remote servers.If you encounter other technical issues during practice or have more practical experience to share regarding automated operations, feel free to leave a comment in the discussion area. We will continue to share practical tips to enhance development and operational efficiency.