Check Folder Size in Linux | Warp
Introducing Warp Factories: open, flexible infrastructure for building your own cloud software factory. Learn More
The short answer
On Unix-like operating systems such as Linux and macOS, to output the size of a folder in a human-readable format, you can use the du command (which stands for "disk usage") as follows:
Bash
$ du -sh <path>
Where:
- The -s flag is used to specify a directory depth of 0 (i.e. equivalent to -d 0).
- The -h flag is used to display the size in a human-readable format using automatic unit suffixes, such as K for Kilobytes, M for Megabytes, and so on.
- The path argument is the relative or absolute path to the folder.
For example:
Bash
$ du -sh ~/server
632M /home/johndoe/server
Outputting the size of subdirectories
To also output the size of subdirectories, you can specify the depth using the -d flag as follows:
Bash
$ du -h -d <depth> <path>
Where:
- The depth argument is the number of subdirectories the du command will traverse down.
For example:
Bash
$ du -h -d 1 ~/server
237M /home/johndoe/server/node_modules
325M /home/johndoe/server/.next
32M /home/johndoe/server/public
35M /home/johndoe/server/.git
2.0M /home/johndoe/server/src
632M /home/johndoe/server
Easily retrieve these commands using Warp's AI Command Suggestions feature
If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Suggestions feature:
Entering check folder size in the AI Command Suggestions will prompt a du command that can then quickly be inserted into your shell by doing CMD+ENTER.