I was working with the Droplets and Volumes on DigitalOcean and down the line, I had a question: How much space my Volume is using?
And based on the above question, I would choose to expand or reduce the size of the Volume.
The same can go for Storage on other providers or local machines.
You NEED to know the usage and plan accordingly.
It would be fast and easy to do so in GUI of OS but if you are connected via terminal or GUI is not enabled, it becomes a constant need to be mentally aware of the size.
I came across a few options, like:
du on the command line)
Let's see how
du works. Assuming that I am in my code directory and wanna analyze
casper (the ghost theme)
But that's not very readable; fortunately
-h is here to show the size in human-readable format:
du -h casper/assets
But above outputs are still not that human-readable.
- All the paths matching the said pattern will be shown
- Files are missing
tree utility is a good alternative to obtaining the size of the directories.
tree won't give the size results to you right away; you would have to ask for it.
Let's try to run it on the above example;
To get the size, we will need to add the
-s flag; let's see what it shows:
Still not good, we can't make sense of the size displayed; it is in
We can use the same flag
-h as of
du to get the size human-readable:
If you want just the directories and no files in the output; we can add
-d flag which will show the following output on our
assets directory example:
Now it might be possible that you don't have it installed on your computer.
To install it, you can run the following commands depending on the OS:
brew install tree
sudo apt install tree
sudo yum install tree
WSL (Windows Subsystem for Linux)
Depending on what Linux subsystem you install, you can use one of the above Linux commands
tree can offer
The tree command is capable of more things such as
- coloured output
- permissions in the tree output
Check out the man page for
tree here: https://linux.die.net/man/1/tree or on Command Line:
Use with other utilities
As it is a completely synchronous utility, you can pipe its output to any other CLI utility or tool.
tree -h assets | carbon-now -p presentation
Have you used the
tree command recently?
What other cool flags you have used it with?
If you find this article helpful, please share it with others 🗣
Subscribe to the blog to receive new posts right to your inbox.