Introduction

Have you ever encountered a situation where a Google Drive Shared Drive is running low on storage, but you can’t figure out which folder is the culprit? The Google Drive web UI doesn’t provide an easy way to check folder-level storage usage within Shared Drives.

This article introduces how to use the CLI tool rclone to efficiently investigate storage breakdown in a Shared Drive and identify/delete unnecessary files.

Environment

  • macOS (with Homebrew available)
  • Terminal

1. Installing rclone

brew install rclone

2. Connecting to Google Drive

You can create a remote configuration non-interactively with the following command:

rclone config create mydrive drive scope=drive team_drive=<SHARED_DRIVE_ID>
  • Shared Drive ID: You can obtain this from the Google Drive URL. It’s the <ID> part of https://drive.google.com/drive/u/0/folders/<ID>.
  • scope=drive grants full access. If read-only access is sufficient, use scope=drive.readonly.

After running the command, a browser window will open for OAuth authentication with your Google account. Complete the authentication to finish setup.

Verify the configuration

rclone listremotes
# Output example: mydrive:

3. Checking Folder Structure

List top-level folders

rclone lsd "mydrive:" --drive-team-drive=<SHARED_DRIVE_ID>

Output example:

0 2023-06-20 11:42:28  -1 FolderA
0 2022-05-18 13:37:35  -1 FolderB
0 2022-05-18 13:38:45  -1 FolderC

Count total files

rclone ls "mydrive:" --drive-team-drive=<SHARED_DRIVE_ID> | wc -l

4. Investigating Folder Sizes

This is the core of the article. Use the rclone size command to check the size of each folder.

Check individual folder size

rclone size "mydrive:FolderA" --drive-team-drive=<SHARED_DRIVE_ID>

Output example:

Total objects: 7056
Total size: 21.523 GiB (23110401117 Byte)
Total objects with unknown size: 324 (324)

Note: Total objects with unknown size refers to Google Docs/Sheets/Slides native format files. These do not count toward Google Drive storage quota.

Compare multiple folder sizes at once

You can use a shell script to check multiple folder sizes in one go:

for dir in "FolderA" "FolderB" "FolderC"; do
  echo -n "$dir: "
  rclone size "mydrive:$dir" --drive-team-drive=<SHARED_DRIVE_ID> | grep "Total size"
done

Output example:

FolderA: Total size: 17.98 GiB (19310319183 Byte)
FolderB: Total size: 1.46 GiB (1570625050 Byte)
FolderC: Total size: 54.188 MiB (56820405 Byte)

Sort by size

Using JSON output and sorting by byte count allows you to efficiently identify the largest folders:

base="ParentFolder/ChildFolder"
for d in $(rclone lsd "mydrive:$base" --drive-team-drive=<SHARED_DRIVE_ID> | awk '{print $NF}'); do
  bytes=$(rclone size "mydrive:$base/$d" --drive-team-drive=<SHARED_DRIVE_ID> --json | \
    python3 -c "import sys,json; print(json.load(sys.stdin).get('bytes',0))")
  echo "$bytes $d"
done | sort -rn | head -20

5. Checking File/Folder Creators

In Shared Drives, it’s also important to know who created or last modified a folder. Since rclone’s standard output doesn’t include owner information, we call the Google Drive API directly.

Reuse rclone’s OAuth token

You can reuse the OAuth token that rclone holds:

# Extract access token from rclone config
token=$(rclone config show mydrive | grep token | python3 -c "
import sys, json
line = sys.stdin.read()
idx = line.index('{')
print(json.loads(line[idx:]).get('access_token', ''))
")

Get folder IDs

Use rclone lsjson to get folder IDs:

rclone lsjson "mydrive:target/path" --drive-team-drive=<SHARED_DRIVE_ID> --dirs-only --no-modtime

The output includes the folder’s ID.

Check creator/modifier via Google Drive API

folder_id="FOLDER_ID_HERE"
curl -s "https://www.googleapis.com/drive/v3/files/$folder_id?fields=name,owners,createdTime,lastModifyingUser&supportsAllDrives=true" \
  -H "Authorization: Bearer $token" | python3 -m json.tool

Output example:

{
    "name": "TargetFolder",
    "createdTime": "2023-06-02T02:37:50.146Z",
    "lastModifyingUser": {
        "displayName": "yamada-taro",
        "me": false
    }
}

Note: Files in Shared Drives have no “owner”, so the owners field is not returned. Use lastModifyingUser to check the last modifier instead.

Watch out for API rate limits

rclone operations and direct API calls share the same quota. If you call the API immediately after intensive rclone operations, you may hit rate limits (rateLimitExceeded). In that case, wait a few minutes before retrying.

6. Identifying Unnecessary Files

Search files by keyword

Useful for finding temporary or work-in-progress files:

# Search for files with specific keywords in their names
rclone ls "mydrive:" --drive-team-drive=<SHARED_DRIVE_ID> | grep -iE "(tmp|test|backup|copy|work)"

Identify large files

rclone ls "mydrive:" --drive-team-drive=<SHARED_DRIVE_ID> | sort -rn | head -20

7. Deleting Unnecessary Files

Delete a file

rclone delete "mydrive:path/to/file" --drive-team-drive=<SHARED_DRIVE_ID>

Delete an entire folder

rclone purge "mydrive:path/to/folder" --drive-team-drive=<SHARED_DRIVE_ID>

Dry run before deletion

It is strongly recommended to use the --dry-run flag to verify targets before actually deleting:

rclone delete "mydrive:path/to/folder" --drive-team-drive=<SHARED_DRIVE_ID> --dry-run

8. A Practical Example

Here is the procedure used when investigating a Shared Drive (approximately 21.5 GB, 7,200 files).

Step 1: Check top-level storage

FolderA (shared documents):   21.52 GB
FolderB (meeting minutes):      54 MB
FolderC (meeting materials):    33 MB

FolderA accounts for over 99% of the total.

Step 2: Drill down into FolderA

SubfolderX:    17.98 GB  ← huge
SubfolderY:     1.46 GB
SubfolderZ:      828 MB
...
tmp:              1.9 MB

SubfolderX accounts for 83% of the total.

Step 3: Further drill down

SubfolderX contained 81 subfolders. A shell script was used to check all sizes at once, identifying the top folders and reviewing their contents before deciding on deletion.

Step 4: Check creators

Using the Google Drive API, we checked the last modifier of the top folders by size. All turned out to be the same person, with the same creation date (the date of bulk migration to the Shared Drive). This helped identify who to consult about deletion.

Summary

  • The Google Drive web UI makes it difficult to understand per-folder storage usage
  • rclone enables hierarchical storage investigation of Shared Drives from the CLI
  • The combination of rclone size and shell scripts allows efficient comparison of many folders’ sizes
  • Always use --dry-run before deletion

rclone supports many cloud storage services beyond Google Drive, so the same techniques can be applied to OneDrive, S3, Dropbox, and more.