Skip to content

Instantly share code, notes, and snippets.

@gregorylearns
Last active March 23, 2025 04:00
Show Gist options
  • Save gregorylearns/ebae8f0519823c309ef7036ef6bca8eb to your computer and use it in GitHub Desktop.
Save gregorylearns/ebae8f0519823c309ef7036ef6bca8eb to your computer and use it in GitHub Desktop.
Tutorial: How to Get Detailed Storage Usage in Google Drive Using Ncdu and Google Colab

This tutorial will guide you through the process of using ncdu (NCurses Disk Usage) in Google Colab to analyze and save detailed storage usage information from your Google Drive.

Requirements

  • Google Colab: A free cloud service that allows you to run Python code in a Jupyter notebook environment.

Steps

1. Access Google Colab

Open your web browser and go to Google Colab.

2. Mount drive and install Ncdu

In a new code cell, run the following command to mount your google drive. Click continue on the prompt asking for permission.

from google.colab import drive
drive.mount('/content/drive')

In a new code cell, run the following command to update the package list and install ncdu:

!apt update && apt install -y ncdu

3. Run Ncdu and Save Output

After installing ncdu, run the following command to analyze your Google Drive storage and save the output to a text file:

!ncdu -o google_drive_ncdu.txt

This command will generate a detailed storage usage report and save it as google_drive_ncdu.txt.

4. Download the Output File

Once the command completes, you can download the google_drive_ncdu.txt file:

On the left sidebar of Google Colab, click on the Files tab.

Locate google_drive_ncdu.txt in the file list.

Click the three dots next to the file and select Download.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment