Macos File System
Overviewπ
macOS uses APFS (Apple File System) by default since macOS High Sierra (10.13). The filesystem structure combines Unix/BSD traditions with Apple-specific directories.
Key Features:
- APFS with snapshots, encryption, and space sharing
- Case-insensitive by default (case-preserving)
- Extended attributes for metadata
- Resource forks (legacy)
- Gatekeeper quarantine attributes
Filesystem Hierarchyπ
Root Directory (/)π
/
βββ Applications/ # Installed applications
βββ Library/ # System-wide libraries and support files
βββ System/ # macOS system files (read-only)
βββ Users/ # User home directories
βββ Volumes/ # Mounted volumes
βββ bin -> usr/bin # Essential binaries (symlink)
βββ dev/ # Device files
βββ etc -> private/etc # System configuration (symlink)
βββ home -> /System/Volumes/Data/home # Legacy
βββ opt/ # Optional software
βββ private/ # Private system files
βββ sbin -> usr/sbin # System binaries (symlink)
βββ tmp -> private/tmp # Temporary files (symlink)
βββ usr/ # Unix system resources
βββ var -> private/var # Variable data (symlink)/Applications - Installed Appsπ
/Applications/
βββ Safari.app
βββ Mail.app
βββ TextEdit.app
βββ Utilities/
# User-specific applications
~/Applications/
# View app bundle
ls -la /Applications/Safari.app/
# Contents/
# MacOS/ # Executable
# Resources/ # Icons, nibs, etc.
# Info.plist # App metadata/Library - System Librariesπ
/Library/
βββ Application Support/ # App support files
βββ Caches/ # System caches
βββ Fonts/ # System-wide fonts
βββ Frameworks/ # Shared frameworks
βββ LaunchAgents/ # User launch agents
βββ LaunchDaemons/ # System launch daemons
βββ Preferences/ # System preferences
βββ Logs/ # System logs
βββ Developer/ # Developer tools
# Examples
ls /Library/LaunchDaemons/
ls /Library/Fonts//System - macOS Systemπ
/System/
βββ Applications/ # System apps (Mail, Safari, etc.)
βββ Library/ # System libraries
β βββ Frameworks/ # System frameworks
β βββ CoreServices/ # Core system services
β βββ Extensions/ # Kernel extensions
β βββ LaunchDaemons/ # System daemons
βββ Volumes/
βββ Data/ # User data volume
# Read-only system volume (macOS Catalina 10.15+)
# Mounted separately from user data/Users - User Home Directoriesπ
/Users/
βββ Shared/ # Shared files between users
βββ username/
βββ Desktop/
βββ Documents/
βββ Downloads/
βββ Library/ # User-specific library
β βββ Application Support/
β βββ Caches/
β βββ Preferences/
β βββ Logs/
β βββ Mobile Documents/ # iCloud Drive
βββ Movies/
βββ Music/
βββ Pictures/
βββ Public/
# Shortcuts
echo $HOME # /Users/username
cd ~ # Go to home directory
cd ~/Documents # Go to Documents~/Library - User Libraryπ
~/Library/
βββ Application Support/ # App data
β βββ com.apple.Safari/
β βββ Google/
β βββ Code/
βββ Caches/ # User caches
βββ Containers/ # Sandboxed app data
βββ Group Containers/ # Shared containers
βββ Keychains/ # Keychain files
βββ Preferences/ # User preferences (.plist files)
βββ Safari/ # Safari data
βββ Mail/ # Mail data
βββ Messages/ # Messages data
βββ Logs/ # User logs
βββ Saved Application State/
βββ Developer/ # Xcode data
# View preferences
defaults read com.apple.finder
ls ~/Library/Preferences/
# Hidden by default (since macOS Lion)
chflags nohidden ~/Library/Volumes - Mounted Volumesπ
/Volumes/
βββ Macintosh HD/ # Main volume (symlinked to /)
βββ Time Machine/ # Time Machine backup
βββ USB Drive/ # External drives
βββ Network Shares/ # Network mounts
# List volumes
ls /Volumes/
diskutil list/private - Private System Filesπ
/private/
βββ etc/ # System configuration
β βββ hosts
β βββ ssh/
β βββ apache2/
β βββ paths
βββ tmp/ # Temporary files
βββ var/ # Variable data
βββ log/ # System logs
βββ db/ # Databases
βββ folders/ # Temporary folders
βββ root/ # Root user home
# Symlinks point here
/etc -> /private/etc
/tmp -> /private/tmp
/var -> /private/var/usr - Unix System Resourcesπ
/usr/
βββ bin/ # User binaries
βββ lib/ # Libraries
βββ local/ # Locally installed software
β βββ bin/
β βββ lib/
β βββ Cellar/ # Homebrew packages
βββ sbin/ # System binaries
βββ share/ # Shared data
β βββ man/ # Manual pages
β βββ doc/
βββ standalone/ # Standalone toolsFile Permissionsπ
Standard Unix Permissionsπ
# View permissions
ls -l file.txt
# -rw-r--r-- 1 user staff 1234 Jan 15 10:00 file.txt
# Change permissions
chmod 755 file.sh
chmod u+x file.sh
chmod -R 755 directory/
# Change ownership
sudo chown user:staff file.txt
sudo chown -R user:staff directory/macOS-Specific Flagsπ
# View flags
ls -lO file.txt
# -rw-r--r-- 1 user staff hidden 1234 Jan 15 10:00 file.txt
# Set hidden flag
chflags hidden file.txt
chflags nohidden file.txt
# Set locked flag
chflags uchg file.txt # User immutable
chflags schg file.txt # System immutable
chflags nouchg file.txt # Remove immutable
# Common flags
# hidden - Hide from Finder
# uchg - User immutable
# schg - System immutable
# nodump - Exclude from Time MachineExtended Attributes (xattr)π
View Extended Attributesπ
# List files with extended attributes
ls -l@
# -rw-r--r--@ 1 user staff 1234 Jan 15 10:00 file.txt
# List all extended attributes
xattr file.txt
# View specific attribute
xattr -p com.apple.quarantine file.txt
# Show all attributes with values
xattr -l file.txtCommon Extended Attributesπ
# Quarantine (Gatekeeper)
com.apple.quarantine # Downloaded from internet
# Finder info
com.apple.FinderInfo # Finder metadata
# Metadata
com.apple.metadata:kMDItemWhereFroms # Download source
# Resource fork
com.apple.ResourceFork # Legacy resource fork
# Text encoding
com.apple.TextEncoding # Text file encodingManage Extended Attributesπ
# Remove specific attribute
xattr -d com.apple.quarantine file.txt
# Remove all extended attributes
xattr -c file.txt
# Recursively remove quarantine
xattr -dr com.apple.quarantine /path/to/app.app
# Copy with attributes
cp -p file1.txt file2.txt
# Preserve attributes when archiving
tar -c --xattrs -f archive.tar directory/Gatekeeper Quarantineπ
# View quarantine attribute
xattr -p com.apple.quarantine downloaded-file
# Remove quarantine (allow app to run)
xattr -d com.apple.quarantine /Applications/App.app
# Alternative: remove recursively
sudo xattr -rd com.apple.quarantine /Applications/App.app
# Verify removal
spctl --assess --verbose /Applications/App.appAPFS (Apple File System)π
APFS Featuresπ
# Space sharing between volumes
# Copy-on-write (CoW) cloning
# Snapshots
# Encryption (FileVault)
# Crash protection
# View APFS containers
diskutil apfs list
# Container structure
diskutil list
# /dev/disk1 (synthesized):
# 0: APFS Container disk1
# 1: APFS Volume β¨Macintosh HDβ©
# 2: APFS Volume β¨Prebootβ©
# 3: APFS Volume β¨Recoveryβ©
# 4: APFS Volume β¨Dataβ©APFS Snapshotsπ
# List snapshots
tmutil listlocalsnapshots /
# Create snapshot
tmutil localsnapshot
# Delete snapshot
tmutil deletelocalsnapshots 2025-01-15-123456
# Mount snapshot
mkdir ~/snapshot
mount_apfs -s com.apple.TimeMachine.2025-01-15-123456 / ~/snapshot
# Unmount
umount ~/snapshotAPFS Clones (Instant Copy)π
# Clone file (instant, space-efficient)
cp -c original.file cloned.file
# or
cp -cpR original/ cloned/
# Verify clone
ls -li original.file cloned.file
# Different inodes, but shared data blocksDisk Managementπ
Disk Utility Commandsπ
# List all disks
diskutil list
# Information about disk
diskutil info disk0
diskutil info /
# Erase disk
diskutil eraseDisk APFS "New Volume" disk2
# Partition disk
diskutil partitionDisk disk2 1 GPT APFS "Data" 100%
# Mount/Unmount
diskutil mount disk2s1
diskutil unmount disk2s1
diskutil unmountDisk disk2
# Repair disk
diskutil verifyVolume /
diskutil repairVolume /Disk Usageπ
# Disk usage
df -h
diskutil info / | grep "Volume Free Space"
# Directory size
du -sh directory/
du -h -d 1 .
# Largest directories
du -hd 1 / | sort -rh | head -20
# Storage management
# System Preferences > General > Storage
# or
open ~/Library/Messages # Check iMessage storageSpotlight and Metadataπ
Spotlightπ
# Search with Spotlight
mdfind "kind:image"
mdfind "kind:pdf date:today"
mdfind -name "document.pdf"
mdfind -onlyin ~/Documents "project"
# Metadata query
mdls file.pdf
# Common attributes
kMDItemKind
kMDItemContentType
kMDItemWhereFroms
kMDItemDateAdded
# Rebuild Spotlight index
sudo mdutil -E /
sudo mdutil -i on /Disable Spotlightπ
# Disable indexing
sudo mdutil -i off /
# Delete index
sudo mdutil -E /
# Prevent indexing (create .metadata_never_index)
touch /Volumes/Drive/.metadata_never_indexFile System Case Sensitivityπ
Default: Case-Insensitiveπ
# macOS default is case-insensitive but case-preserving
# FILE.txt and file.txt are the same file
# Test
touch FILE.txt
ls file.txt
# FILE.txt (can access with any case)Case-Sensitive APFSπ
# Create case-sensitive volume
diskutil apfs addVolume disk1 "Case-sensitive APFS" "CaseSensitive"
# Format options
# APFS - Case-insensitive
# "Case-sensitive APFS" - Case-sensitive
# "APFS (Encrypted)" - Encrypted, case-insensitive
# "Case-sensitive APFS (Encrypted)" - Encrypted, case-sensitiveSpecial Directoriesπ
Application Supportπ
# System
/Library/Application Support/
# User
~/Library/Application Support/
# Example paths
~/Library/Application Support/Code/
~/Library/Application Support/Google/Chrome/
~/Library/Application Support/Sublime Text/Preferencesπ
# Stored as .plist files
~/Library/Preferences/com.apple.Safari.plist
~/Library/Preferences/com.apple.finder.plist
# Read preferences
defaults read com.apple.finder
# Write preferences
defaults write com.apple.finder AppleShowAllFiles true
# Delete preference
defaults delete com.apple.finder AppleShowAllFiles
# Reload Finder
killall FinderCachesπ
# System cache
/Library/Caches/
/System/Library/Caches/
# User cache
~/Library/Caches/
# Clear user caches
rm -rf ~/Library/Caches/*
# Clear system caches (requires sudo)
sudo rm -rf /Library/Caches/*Hidden Filesπ
View Hidden Filesπ
# In Finder
# Press: Cmd + Shift + .
# In Terminal (always visible)
ls -la
# Show all files in Finder (permanently)
defaults write com.apple.finder AppleShowAllFiles true
killall Finder
# Hide again
defaults write com.apple.finder AppleShowAllFiles false
killall FinderCommon Hidden Filesπ
~/.bashrc, ~/.zshrc # Shell configuration
~/.ssh/ # SSH keys
~/.config/ # XDG config
~/.Trash/ # User trash
.DS_Store # Finder metadata
.localized # Localization hintSystem Integrity Protection (SIP)π
Check SIP Statusπ
csrutil status
# System Integrity Protection status: enabledProtected Directoriesπ
# SIP protects these even from root:
/System
/usr (except /usr/local)
/bin
/sbin
/var
# Can't modify even with sudo
sudo rm /System/Library/SomeFile
# Operation not permittedDisable SIP (not recommended)π
# 1. Boot into Recovery Mode (Cmd+R)
# 2. Open Terminal
csrutil disable
# 3. Reboot
# Re-enable
csrutil enableFinder Integrationπ
Open in Finderπ
# Open current directory
open .
# Open specific directory
open ~/Documents
# Open with application
open -a "Visual Studio Code" file.txt
open -a Safari https://example.com
# Reveal in Finder
open -R file.txtQuick Lookπ
# Preview file
qlmanage -p file.pdf
# Clear Quick Look cache
qlmanage -r
qlmanage -r cacheTime Machineπ
Time Machine Directoriesπ
# Local snapshots
/.MobileBackups/
# Backups on external drive
/Volumes/Time Machine/Backups.backupdb/ComputerName/
# Exclude from backup
tmutil addexclusion ~/large-directory/
tmutil removeexclusion ~/large-directory/
# List exclusions
tmutil isexcluded ~/directory/Best Practicesπ
Organizationπ
- Store user files in ~/Documents, ~/Downloads, etc.
- Use ~/Library/Application Support for app data
- Keep ~/Library clean (many apps donβt clean up)
- Use iCloud Drive for cloud storage
Securityπ
- Remove quarantine only from trusted apps
- Be cautious with sudo commands
- Keep SIP enabled
- Use FileVault for disk encryption
- Regular Time Machine backups
Performanceπ
- Clear caches periodically
- Use APFS snapshots before major changes
- Monitor disk space
- Disable Spotlight on external drives if not needed
Maintenanceπ
- Clean ~/Library/Caches regularly
- Remove old iOS backups from ~/Library/Application Support/MobileSync/
- Check ~/Downloads for old files
- Use Storage Management (About This Mac > Storage)
Resourcesπ
- Apple File System Reference: https://developer.apple.com/documentation/foundation/file_system
- File System Programming Guide: https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/
- man pages:
man xattr,man diskutil,man tmutil - APFS documentation: https://support.apple.com/guide/disk-utility/