2024-11-24
Alias to check Storage from terminal on macOS
Here are common ways to check storage on macOS
-
-> About This Mac -> More Info... -> Storage
-
System Settings -> General -> Storage
-
Using Raycast or Alfred: search for "Storage"
Here's how to create an alias to check storage on terminal, but I wanted to see free space rather than used space
Alias
~/.zshrc
Usage and output
Breakdown of the alias
diskutil info /
Displays disk information for the root volume /
.
| grep 'Container'
Filters lines containing "Container"
| awk
Processes and extracts values
-
/Free Space/ {free=$4; unit=$5}
Captures the line with "Free Space", and assign 4th column to variable
free
, 5th column tounit
-
/Total Space/ {total=$4}
Captures the line with "Total Space", and assign 4th column to variable
total
-
{print free, unit, "of", total, unit, "free"}
Print the text with variables assigned