Tools and techniques to minimize disk space usage
This article describes how you can manage and minimize disk space usage on macOS (compared vs. Linux).
If you have a way to live comfortably with a 256 GB drive vs. a 500 GB drive on your Mac, you save several hundred dollars.
A 4TB USB external mechanical hard disk costs less than $100 at Costco.
A 2TB USB external mechanial drive costs less than a $100 at Apple.
The more files on your laptop, the more you stand to lose and the longer it takes to restore your laptop when you (inevitably) have to recover it.
Not having enough free disk space may cause your fan to come on, which is an indicator that your mac may be overheating.
Take Disk Inventory
Visualize the largest files using your disk space using the free GPL app Disk Inventory X from http://www.derlien.com which presents the sizes of files and folders in graphical “treemaps”.
PROTIP: Log files can fill out a drive gradually over time. So monitor its size regularly.
Macs Read, Not Write NTFS
Windows machines natively formats drives using NTFS (New Technology File System). Additionally, to handle drives larger than 2GB, Windows 10 is moving from MBR (Master Boot Record), first introduced with IBM PC DOS 2.0 in 1983, to GPT (GUID Partition Tables). On Linux, the GRUB boot loader is typically located in the MBR. Since GPT identifies every partition on a drive using a GUID, it escapes the MBR limitation of up to four primary partitions. However, Windows allows up to 128 partitions on a GPT drive.
A big advantage of GPT is that it duplicates partition information in several places on the drive. Apple’s Intel Macs no longer use Apple’s APT (Apple Partition Table) scheme and use GPT instead.
Apple limited support for Windows volumes by allowing only read but not write or delete anything on NTFS drives.
Windows 7 does not work with drives 2.16 TB or more. When plugged in, 3TB and 4TB drives don’t even appear in the Folder.
However, for $19.99 Paragon software enables your Mac to write and delete files on NTFS drives.
Remove Unneeded Language
One quick and simple way of recovering disk space is this:
brew install monolingual
Then invoke the program.
Since I’m in the imperious US, I selected for removal all languages except US(en), US(gb).
Delete your copy of repos on your local hard disk when you are not actively editing a particular repo.
The /opt folder is where many Linux users put various custom software they develop.
PROTIP: Write bash scripts so that files are deleted on exit.
Use trash utility, not rm command
When the built-in
rm command is used to remove a file or folder, they are gone because it calls the System API rather than moving the file to the macOS Trash folder:
rm -rf folder1
-r (recursive) specifies deleting all sub-folders.
PROTIP: Install the
trash utility (from sindresorhus.com)
to delete files such that they can be un-trashed:
brew install trash touch checkitout remove checkitout
The program conflicts with trash-cli at https://github.com/sindresorhus/trash, along with companion commands macos-trash, empty-trash, and del which use the same Trash in FreeDesktop.org of KDE, GNOME, and XFCE.
/dev (devices) folder
VIDEO: On Linux, everything is a file.
cd /dev && ls -al
The /dev folder on Macs and Linux contain files which point to both physical and pseudo devices.
b in the first character of the listing describes a block device.
sda is the default drive. Additional drives are sdb, etc.
sda1 is the first partition (no zero here).
/tmp (temporary) folder should be empty on boot-up because reboot wipes out its contents.
/usr (user) level files which the PATH configures to override files of the same name in the system folder (a program in /usr/bin is used instead of one with the same name in /bin)
X11 bin lib libexec local sbin share standalone
/var (various) files go in this folder, particularly log files in /var/log.
PROTIP: Admins of production servers allocate this /var/log folder in its own drive partition so that if logs fill up, it won’t consume all the space and crash the server.
BTW Unlike Linux, MacOS does not have these folders:
- /lib libraries of dynamic (.so) and static (.a)
- /proc folder virtual filesystem, containing a folder for each process.
- /root folder for use by the root user
- /etc holds system utilites such as dpkg, which contains a dpkg.cfg configuration file.
Benchmark disk write speed
mkdir ram cd ram/ dd if=/dev/zero of=test.iso bs=1M count=8000 rm test.io
8000+0 records in 8000+0 records out 838860800 bytes (8.4 GB, 7.8 GiB) copied, 44.2673 s, 189 MB/s
TODO: Test vs. USB 3 drive.
Disk space uses & available
Find out how much RAM you have used and available: launch Activity Monitor. Find it in the Launcher or in Finder, navigate to /Applications/Utilities/. Click its Memory tab/button.
In the example above, 16 - 13 used means 3 GB is available. Subtract 2GB for system use leaves you 1GB for use as RAM disk. Summarizing Apple’s About Memory:
- Wired memory: (also called resident memory) can’t be moved to the hard disk, so it must stay in RAM. The amount of Wired memory depends on the applications you are using. “Wired” memory is used for core functions of the operating system, space for like a card catalog.
- Active memory: is currently in memory, and has been recently used.
- Inactive memory: is not actively being used, but was recently used.
- Used: is the total amount of memory used.
- Free memory: is RAM that’s not being used.
Alternately,*, define an alias in aliases.sh macOS command:
alias free="top -l 1 -s 0 | grep PhysMem"
which responds with something like:
PhysMem: 16G used (3060M wired)n 383M unused.
There is also vm_stat which provides a lot more detail, but requires some math calculation since it reports the number of 4096-byte blocks rather than “383M”.
A drive running in your RAM rather than on your hard drive is much faster (5 - 100 times faster).
RAM Disk on macOS
Before proceeding further, do a full backup of your whole machine to a USB drive.
Consider third-party utilities for creating a RAM disk.
Open-source (free) https://github.com/imothee/tmpdisk installs as a menu bar item to create RAM disks by GUI or automatically at startup.
Construct the RAM disk creation command: If you have a HFS+ drive:
diskutil erasevolume HFS+ "RAMDisk" `hdiutil attach -nomount ram://1048576`
PROTIP: Allocate the smallest amount, then add as you need.
- ram://2048 (multiply by 2048 for a 1 MB RAM disk)
- ram://524288 (multiply by 2048 for a 256 MB RAM disk)
- ram://1048576 (multiply by 2048 for a 512 GB RAM disk)
- ram://2097152 (multiply by 2048 for a 1 GB RAM disk)
- ram://4194304 (multiply by 2048 for a 2 GB RAM disk)
Notice the use of back tick enclosing characters.
RAM Disk on Linux
By contrast, in Linux, see the amount of RAM:
Use the mkdir command to create a folder to use as a mount point for your RAM disk (mkdir /mnt/ramdisk):
mkdir -p /mnt/ramdisk1
Create a RAM disk using FSTYPE tempfs, which replaced ramfs*
mount -t tmpfs tmpfs /mnt/ramdisk1 -o size=512m
The RAM disk can persist over reboots if specified in file /etc/fstab,
tmpfs /mnt/ramdisk tmpfs nodev,nosuid,noexec,nodiratime,size=512M 0 0
PROTIP: Remember that data in RAM drives disappear each time the machine is restarted.
- Apple iCloud in the US charges per month 50GB: $0.99, 200GB: $2.99, 2TB: $9.99
- drive.google.com goes straight to a 2TB plan for $10 per month.
- Google Cloud charges for egress.
- Amazon’s Drive (for Prime members to store an unlimited number of photo files)
- Microsoft’s OneDrive, etc.
- Verizon charges $5 per month for 50GB (to store images and such from mobile phones).
PROTIP: The problem with cloud drives is that it takes time to drag each file from Finder to the web page.
Cloud vendors have programs, but they take up disk space, which defeats much of the purpose of using cloud storage.
More on macOS
This is one of a series on macOS (Mac OSX):
- MacOS Hardware and accessories
- MacOS Boot-up
- MacOS Terminal Tips and Tricks
- MacOS Keyboard tricks
- Text editors and IDEs on MacOS
- MacOS Setup automation
- MacOS Homebrew installers
- Manage Disk Space on MacOS
- Data Backups on MacOS
- Ports open
- Applications on MacOS
- Windows on Apple MacOS
- Packer create Vagrant Windows image
- Python on MacOS
- Maven on MacOS
- Ruby on MacOS
- Java on MacOS
- Node on MacOS installation
- PHP on MacOS
- Scala ecosystem