Category filter
Script to check disk usage on macOS devices
Administrators may need to check the disk usage of corporate devices frequently as part of standard security monitoring. This can help prevent your system from slowing down due to lack of disk space. However, administrators can now remotely achieve this by utilizing Hexnode’s custom scripting functionality rather than physically inspecting each device.
Scripting Language – Bash
File extension – .sh
Find disk usage
1. Disk usage of all users
1 |
sudo du -hxd1 /Users |
This command returns a list of all the users and their individual disk space usage.
2. Disk usage of the entire/specific file system
1 |
df -h[filesystem] |
This command lists the available disk space and used disk space in a human-readable format. If a mount point is provided as an argument to the df command, I.e., a filesystem, the command lists out data of that particular filesystem only.
e.g.,df -h /dev/sda.
This command lists information only for the partition /dev/sda in a human-readable format.
3. Disk usage of the current directory
1 |
du -sh * |
The * covers all the files present in your home or current directory, and passing the -sh option summarises the disk usage for the given directory in a human-readable format.