1. Download the Tool - qshell
qshell is a command-line tool built on the public APIs documented by Qiniu to make it easy for developers to test and use Qiniu API services, written in the Go language. The tool currently bundles convenient commands for Qiniu Storage, CDN, and other methods commonly used in Qiniu services.
| Version | Supported Platforms | Link | Changelog |
|---|---|---|---|
| qshell v2.0.7 | Linux (32-bit, 64-bit, arm platforms), Windows (32-bit, 64-bit), Mac OSX (32-bit, 64-bit) | Download | View |
Download the qshell zip package and extract it. You will find qshell command files for several systems inside. Choose the file that suits your system and rename it to qshell. So that the qshell command can be used from any directory, it is recommended to copy the qshell file into one of the directories in PATH. For example, I installed Go and added its bin directory to PATH, so I just copy qshell into the C:/Go/bin/ directory.
2. Setting the Account Key
The new version of qshell requires account information to be set in a separate file. Replace Administrator below with the corresponding account name. After logging into Qiniu, the key can be viewed on the page under [Personal Panel] - [Key Management]. With the old version of the qshell command, the key is set in the command’s configuration file parameter.
| |
Or set it with a command
| |
3. Batch Upload
Command format: qshell qupload [concurrency] [config file name]
| |
| |
The command above uploads the files under the qiniu/upload_dir directory on drive D to the bucket named mybucket, at a rate of twenty times per second.
For example, if there is a file D:/qiniu/upload_dir/te/tex.txt, after uploading there will be a file te/tex.txt in mybucket; the directory structure is preserved. For more settings, please refer to the official documentation.
Tips: It is recommended not to set the concurrency too high, or files will be missed during upload.
4. Batch Download
Command format: qshell qdownload [concurrency] [config file name]
| |
The command above downloads all files starting with test/ from mybucket in the http://xxx.com1.z0.glb.qiniucdn.com space, at a rate of twenty times per second, and saves them locally under the D:/qiniu/download_dir directory.
For example, if there is a file test/te/tex.txt in mybucket, after downloading there will be D:/qiniu/download_dir/test/te/tex.txt; the directory structure is preserved. For more settings, please refer to the official documentation.
5. Batch Delete
Command format: qshell batchdelete [-force] [bucket name] [text file holding the file names to delete]
Deletion cannot be undone. Out of caution, running batchdelete requires entering a verification code. If you do not want to enter the verification code, you can pass the optional -force parameter.
The tricky part here is how to obtain the [text file holding the file names to delete].
| |
On Linux you can use the find command directly; on Windows you need Cygwin to run the find command. In my own practice, I first downloaded the directory to be worked on to the download_dir directory with the qdownload command. Then, in the download_dir directory, I ran the command above to export the list of all file names under the my_dir directory.
| |
Finally, run the batchdelete command to delete the files in the specified bucket. Here it deletes the files under mybucket that correspond to the file names in the file_name_list.txt above.
| |
