List folder size on current directory on Mac
List folder size
List folder size
When the disk is almost full, we usually want to find which folder has most files, in mac, we can use du command to list files, we can use the following command.du -h -d 1
The command above has two parameters:
-hshow the size as human readable, such as MB, GB, KB-d 1This parameter means show one level folder size, so the list will contain the directory on current directory.
Sometimes the command will reportPermission denied error, in order hide this error message, we can add another parameter like the command below:du -h -d 1 2>/dev/null
The parameter 2>/dev/null means print error message to /dev/null , so the error message won’t show on the output.
Sort result with size
We can add sort command after the du command to sort result, the command is like below:du -h -d 1 2>/dev/null | sort -h
Sort the result in DESC orderdu -h -d 1 2>/dev/null | sort -h -r