rclone

How to calculate Google Drive folder size (space used) using RCLONE?


Google Drive does not give you a break down of each folder size individually, so when getting close to the limit of storage, it would be nice to know which folders are taking up the most space.

How can I use rclone (rclone.org) to get the size of a folder and how much space it is using, on Google Drive?


Solution

  • To get the total space used by your entire Google Drive use this:

    rclone size "myGoogleDrive:/"
    

    To get the total size (space used) of one particular folder, use this:

    rclone size "myGoogleDrive:myFolderName/"
    

    Thanks to the following post for helping figure this out: https://www.guyrutenberg.com/2017/08/23/calculate-google-drive-folder-size-using-rclone/

    WINDOWS PHP SCRIPT TO FIND ALL TOP LEVEL FOLDER SIZES:

    Note that the following script is written in PHP on Windows. You need to make sure shell_exec() command is not disabled in php.ini. You can run the script from command line or powershell using php filename.php

    It assumes you have rclone installed and included in your windows environment path.

    It will first retreive a list of all top level folders from your Google Drive, and then breaks the returned string into an array.

    It will then loop thru the array and pull each directory name out and get its size.

    <?php
        echo "\r\nGOOGLE DRIVE - Total Storage Space Used (by top level directories)\r\n\r\n";
        echo "Running RCLONE LSD...\r\n\r\n";
        $dir_list_string = shell_exec('rclone lsd myGoogleDrive:'); // Get top level directory listing
        echo "FOUND THESE...\r\n";
        echo $dir_list_string."\r\n\r\n";
        echo "Running RCLONE SIZE...\r\n\r\n";
        $dir_list = explode("-1 ", $dir_list_string); // Split the returned string into an array
        $count_list = count($dir_list); // How many items in the array?
        for ($i = 2; $i < $count_list; $i=$i+2) {
            $dir_list[$i] = trim($dir_list[$i]); // Get rid of white space around name
            echo "Checking size of: ".$dir_list[$i]."\r\n";
            $size_string = shell_exec('rclone size "myGoogleDrive:'.$dir_list[$i].'/" '); // Get size of each directory
            echo $size_string."\r\n";
        }
        $size_all = shell_exec('rclone size "myGoogleDrive:/" ');
        echo "TOTAL SPACE USED FOR ENTIRE GOOGLE DRIVE:\r\n";
        echo $size_all."\r\n";
        echo "DONE\r\n\r\n";
    ?>