在网络控制台中,是否有一种方法可以根据日期,大小,类型等对Google存储桶中的文件进行排序

找不到对此的任何引用。似乎是任何文件存储的基本功能。

iCMS 回答:在网络控制台中,是否有一种方法可以根据日期,大小,类型等对Google存储桶中的文件进行排序

当前,无法在Cloud Console上对存储桶中的文件或文件夹进行排序。

您始终可以通过编码排序例程来做到这一点:

// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');

// Your Google Cloud Platform project ID
const projectId = 'YOUR PROJECT';

// Creates a client
const storage = new Storage({
  projectId: projectId,});

// The name for the new bucket
const bucketName = 'YOUR-BUCKET';
const bucket = storage.bucket(bucketName);
bucket.getFiles(null,(err,data) => {
    data.sort((a,b) => {
        if (a.metadata.updated > b.metadata.updated) {
            return 1;
        }
        if (a.metadata.updated < b.metadata.updated) {
            return -1;
        }
        return 0;
    });
    for (file of data) {
        console.log(` ${file.metadata.name} - ${file.metadata.updated}`);
    }
});

有一个功能请求,但似乎未更新。

https://issuetracker.google.com/issues/119209458

,

替代正在为此(gcloud / gsutil)使用命令行

假设您已经安装了gcloud ...下一步:

使用已登录的终端(检查/设置)GCP项目:

T_MY_TABLE_X.ID-检查您是否使用了正确的GCP项目。

$> gcloud config list-设置所需的项目

获取存储桶/文件夹的总大小:

$> gcloud config set project <your_project_id>

列出按日期升序排列的对象:

gsutil du -sah gs://bucket_name/folder1

列出按大小降序排列的对象:

gsutil ls -l gs://bucket_name/folder1/folder2 | sort -k 2

按前缀列出唯一的对象(例如对象名称模式:twitter_2020-09-03-03-01-10.csv,facebook_2020-09-03-03-01-11.csv):

gsutil du -ah gs://bucket_name/folder1/folder2/* | sort -k 2

(在最后一个示例中)如果您在该文件夹中有多个twitter,facebook文件,结果将为:

gsutil ls gs://bucket_name/folder_name | sed 's/_.*//' | uniq
本文链接:https://www.f2er.com/1765109.html

大家都在问