keepcalculator

06 Numbers and Powers

10 macOS Command Line Utilities You Might Not Know

Card No. 06·62272 · Updated · Standard formula, shown below

This article introduces ten lesser-known macOS command-line utilities that can help you manage files, inspect system information, and automate tasks more efficiently. Each utility is explained with its purpose, common options, and a practical example, so you can start using them right away in Terminal.

Background: The Power of the Unix Layer

macOS is built on a Unix foundation (Darwin), which means every Mac includes a rich set of command-line tools inherited from BSD and GNU projects. While most users interact with the graphical interface, the terminal offers direct access to system internals, often with more speed and flexibility. Many of these utilities are not documented in the standard macOS user guides, so they remain hidden gems for developers, system administrators, and power users.

1. mdfind – Spotlight from the Terminal

mdfind lets you query the same metadata index that powers Spotlight, but with more control. You can search by file name, content, or metadata attributes like date, size, or kind.

  • Basic search: mdfind "kind:pdf" finds all PDFs.
  • Name search: mdfind -name "report" finds files with “report” in the name.
  • Only filenames: mdfind -onlyin . "string" limits the search to the current folder.

This is faster than find for content searches because it uses the pre-built index.

2. pbcopy and pbpaste – Clipboard Magic

These two commands bridge the terminal and the macOS clipboard. pbcopy takes standard input and puts it on the clipboard; pbpaste outputs the clipboard contents.

cat file.txt | pbcopy   # copy file content
pbpaste > pasted.txt    # save clipboard to file

You can also pipe command output directly to the clipboard, which is handy for sharing error messages or saving a directory listing.

3. sips – Image Processing Without Photoshop

sips (Scriptable Image Processing System) is a built-in tool for resizing, cropping, rotating, and converting image formats. It supports common formats like JPEG, PNG, TIFF, and HEIC.

  • Resize: sips -Z 800 image.jpg scales the image to fit within 800×800 pixels.
  • Convert: sips -s format png image.jpg --out image.png converts to PNG.
  • Rotate: sips -r 90 image.jpg rotates 90 degrees clockwise.

You can process multiple files in a loop, making it ideal for batch operations.

4. textutil – Document Converter

textutil converts between text formats: RTF, HTML, plain text, Word (.docx), and more. It can also extract text from these files.

textutil -convert html notes.rtf -o notes.html
cat notes.txt | textutil -stdin -stdout -convert html

This is useful for quick conversions without opening a word processor.

5. defaults – Read and Write User Preferences

defaults gives you access to the user defaults system, which stores preferences for apps and the system. You can read, write, and delete keys.

  • Read: defaults read com.apple.finder AppleShowAllFiles
  • Write: defaults write com.apple.finder AppleShowAllFiles -bool true
  • Delete: defaults delete com.apple.finder AppleShowAllFiles

Many hidden settings are only accessible this way. After changing some settings, you may need to restart the app or the Finder.

6. plutil – Property List Utility

plutil lets you inspect and manipulate property list files (.plist), which store configuration data. You can convert between XML and binary formats, and check syntax.

plutil -convert xml1 file.plist   # convert to XML
plutil -lint file.plist           # check syntax

This is essential for developers working with app preferences or configuration files.

7. fsck – File System Consistency Check

fsck checks and repairs the file system. On modern macOS, it’s usually run automatically at boot, but you can run it manually on a mounted volume (with caution).

sudo fsck -fy /dev/disk1s1   # check and fix (use with care)

Warning: Running fsck on a mounted volume can cause data loss. It’s safer to boot into Recovery Mode and use Disk Utility’s First Aid.

8. networksetup – Network Configuration

networksetup is a powerful tool for managing network interfaces, DNS, proxies, and more. It can be used to switch networks or troubleshoot connectivity.

  • List services: networksetup -listallnetworkservices
  • Get IP: networksetup -getinfo Wi-Fi
  • Set DNS: networksetup -setdnsservers Wi-Fi 8.8.8.8

This is handy for scripting network changes or diagnosing DNS issues.

9. say – Text-to-Speech

say converts text to spoken audio using macOS’s built-in speech synthesizer. You can output to the default audio device or to an AIFF file.

say "Hello, world"
say -o greeting.aiff "Hello"

You can also adjust voice, rate, and pitch. This is useful for accessibility, notifications, or creating audio files.

10. caffeinate – Prevent Sleep

caffeinate prevents the Mac from sleeping, either indefinitely or for a specified duration. It’s useful during long downloads or presentations.

caffeinate -u -t 3600   # prevent idle sleep for 1 hour
caffeinate -i make      # run a command with sleep disabled

Use -d to prevent the display from sleeping, and -s to prevent the system from sleeping on AC power.

How to Choose the Right Utility

Consider what you need to accomplish. For file search, mdfind is fastest. For clipboard operations, pbcopy/pbpaste are essential. For image tasks, sips covers most needs. If you’re editing preferences, defaults is the way. Each tool has a specific niche, and learning them expands your terminal vocabulary.

Common Problems and Safety

Some utilities like fsck and defaults can be dangerous if misused. Always back up important data before running repair commands. For defaults, be careful with the domain and key names; a typo can cause app issues. When using sips, keep originals unless you’re sure of the result. For networksetup, changes take effect immediately and may disconnect you.

Frequently Asked Questions

Is mdfind faster than Spotlight search?

Yes, for complex queries, because you can specify attributes and paths directly. It uses the same index, so results are instant.

Can I use pbcopy to copy binary data?

Yes, it works with any data, but the clipboard is designed for text. For binary, consider using base64 encoding first.

Does sips support HEIC images?

Yes, on recent macOS versions, it can read and write HEIC, though conversion to JPEG might lose quality.

Is fsck safe to run on my startup disk?

No, you should not run fsck on a mounted startup disk. Use Disk Utility in Recovery Mode instead.

Can I use defaults to change any setting?

Only those exposed by the app’s preferences system. Many settings are undocumented, but you can find them online.

How do I learn more about these commands?

Use man followed by the command name (e.g., man sips) to read the manual page. Also, --help often shows a summary.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →