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

Disclaimer:


The Sample Scripts provided below are adapted from third-party Open-Source sites.

Find disk usage

1. Disk usage of all 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

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

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.

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository