Category filter
Script to find file or folder size on Mac
Have you ever wondered how big a specific file or folder on a Mac is? You can view the file or folder size using the Get Info option by right-clicking on the required file or folder on a Mac. However, manually checking the file or folder size on multiple endpoints may be tiresome for the admins. Now, IT admins can remotely fetch device details like file or folder size by running the Execute Custom Script action on the endpoint devices using Hexnode UEM. This doc includes the Terminal commands to retrieve the file or folder size on macOS devices.
Scripting language – Bash
File extension – .sh
Find file/folder size
1 2 |
#!/bin/bash du –h ‘folder name or file name with extension along with complete file path’ |
The script requires the complete file path, including the filename with its extension, to be provided.
1 2 |
#!/bin/bash du -h /Users/stefan/Desktop/Document.txt |
The above command provides the disc usage for the file ‘Document.txt’
, as shown below:
The du
command is a standard command that allows users to gain disk usage information quickly. Some of the options supported with the command are
-h
- flag prints size outputs in Byte format, this provides a unit of measure.
-a
- flag lists the sizes of all files and directories in the given file path. For example,
du –a ~/Downloads/Wallpapers
-c
- flag adds a line to the bottom of the output that displays the grand total of all the disk usage for the file or folder path given. For example,
du –c ~/Downloads