Dive into Mac terminal commands for web developers. Boost your workflow and master hidden Mac tools. Become a terminal whiz today!
TL;DR;
Hey there! If you’re short on time, this is your quick pit stop. We’re going to breeze through a list of essential Mac terminal commands for web development.
caffeinate
: This command prevents your Mac from going to sleep, which can be helpful when you’re working on a long project.pbcopy
,pbpaste
: These commands allow you to copy and paste text from the terminal to other applications.networkQuality
: This command runs an Internet speed test from your Mac.networksetup
: This command can be used to configure network settings.sips
: This command can be used to resize, crop, and rotate images.open
: This command can be used to open files and applications.textutil
: This command can be used to convert files between different formats.mdfind
,mdls
: These commands can be used to search for files and folders using Spotlight.screencapture
: This command takes screenshots.taskpolicy
: This command can be used to control the scheduling of processes.say
: This command can be used to speak text aloud.pmset
: This command can be used to configure power management settings.qlmanage
: This command can be used to manage Quick Look.softwareupdate
: This command can be used to manage OS updates.system_profiler
: This command can be used to view system information.
Useful Mac Terminal Commands
It’s time to level up your Mac terminal game and make your development process more efficient. If you’re not already using the terminal or command line for your workflow, you’re missing out on a trove of tools that can streamline your tasks. Let’s dive into some powerful macOS terminal commands and tools that you might not know about, but definitely should!
Mastering Mac’s Snooze with caffeinate
Tired of your Mac falling asleep while you’re on a coffee break? Well, meet caffeinate
, a handy Mac terminal command that can keep your Mac awake just like a strong shot of espresso. Run caffeinate
without any flags, and your Mac will stay wide awake as long as the command is running.
$ caffeinate
Flags
-u -i <seconds>
: Won’t sleep for the specified number of seconds.-d
: Prevent your display from going to sleep.-w <pid>
: Link to a process
caffeninate
Flags Explained
Want to control the sleep duration? No problem! Just add -u -t <seconds>
, and your Mac won’t sleep for the number of seconds you specify. And if you hate your display going to sleep, simply adding the -d
flag will keep it awake.
The caffeinate
command can also be linked to a process using -w <pid>
, which automatically stops the caffeinate
command once the process exits. Or, you can start a new process with caffeinate <command>
that keeps your Mac from sleeping until the process ends.
Clipboard Magic with pbcopy
& pbpaste
The dynamic duo of pbcopy
and pbpaste
are your best friends when it comes to interacting with the system clipboard. Pipe any command to pbcopy
like <command> | pbcopy
, and the output gets copied to the clipboard. And when you want to get the contents of the clipboard, pbpaste
outputs it for you. It’s that simple!
$ <command> | pbcopy
$ pbcopy <path to file>
$ pbpaste
Surfing Speeds with networkQuality
Ever needed to quickly check your internet speed while pushing a hefty commit? Well, networkQuality
is your go-to Mac terminal command. Run it to perform an internet speed test right from your terminal.
$ networkQuality
Flags
-v
: Get more detailed info.-i
: Specify a network interface for the speed test.
Tailoring Connections with networksetup
The networksetup
command is a powerful tool for managing your network settings. It allows you to view and configure network hardware settings. Need to quickly switch between Wi-Fi networks or change your IP address? networksetup
makes it easy. It’s a must-have command for any web developer.
$ networksetup
Flags
-listnetworkserviceorder
: Shows a list of available network services.-getinfo <networkservice>
: Displays information about the specified network.-getdnsservers <networkservice>
: Shows the DNS servers for the specified network.-setairportnetwork <device> <network> [password]
: Joins the specified Wi-Fi network (in most cases, the<device>
argument should been0
).
Manipulate Images with sips
Are you tired of switching between your terminal and image editing software? Well, sips
is a hidden gem that lets you manipulate images directly from your terminal. Resize, crop, or rotate images as you please. And the best part? You can even specify a different output file path using the -o
flag to avoid overwriting your original image.
$ sips -z <height> <width> <path to image>
$ sips -Z <size> <path to image>
$ sips -c <height> <width> <path to image>
$ sips -r <degrees> <path to image>
Flags
-o
: Specify a different output file path (must have the same file extension as the input image).-c
: Crop an image, relative to the center of the original image.-z
: Resize an image, ignoring the previous aspect ratio.-Z
: Resize an image, preserving the aspect ratio.-r
: Rotates and image.
By default, sips
will destructively overwrite the input image.
Unlocking Apps and Files with open
The open
command is like the magic wand that can open files and applications directly from your terminal. Use open -a <app> <file>
to open a file with a specific application. Or, just type open .
to open your current directory in a new Finder window.
$ open <path to file>
$ open -a <app> <path to file>
$ open .
Flags
-a <app>
: Open with a specific application.
Convert Documents with textutil
Need to convert files between different formats? Say hello to textutil
, a versatile document file converter. It can convert files to and from Microsoft Word, plain text, rich text, and HTML formats.
$ textutil -convert <format> <filename>
The available options for -convert
are: txt
, html
, rtf
, rtfd
, doc
, docx
.
Spotlight Magic: mdfind
& mdls
The mdfind
and mdls
commands are incredibly useful for searching your Mac using Spotlight, right from your terminal. Whether you’re hunting for files containing specific keywords, or you’re trying to identify the metadata associated with a particular file, these commands are powerful tools to have in your arsenal.
$ mdfind <query>
$ mdfind kMDItemAppStoreHasReceipt=1
$ mdfind -name <name>
$ mdls <file-path>
Flags
-onlyin <dir>
: Restricts the search to the given directory.-name <name>
: Searches all files matching the given name.
Finding out about mdfind
mdfind
performs a Spotlight search for files anywhere on your filesystem that match the given query. It’s like having Spotlight’s convenience and power in your terminal. For instance, if you want to find all files that contain the word invoice, you’d simply use mdfind invoice
.
Searching a Little Deeper with mdls
On the other hand, mdls
lists the metadata attributes for the specified file. This can be useful when you need more information about a specific file. For instance, to get the metadata of a file named example.txt, you would use mdls example.txt
.
Snapping Shots with screencapture
Need to take screenshots while working? screencapture
is the command for you. You can take a screenshot and copy it to the clipboard or save it to a specified file.
$ screencapture -c
$ screencapture <file>
Flags
-T <seconds>
: Take the screenshot after the given delay in seconds.
Bossing Processes Around with taskpolicy
taskpolicy
lets you control the scheduling of processes. Whether you need to start executing a command in the background or downgrade an existing process to run in the background, taskpolicy
gives you the power to manage your processes more efficiently.
$ taskpolicy -b <command>
$ taskpolicy -b -p <pid>
$ taskpolicy -B -p <pid>
$ taskpolicy -s <command>
Flags
-b <command>
: Starts running the given command in the background (on Apple silicon Macs, the process will only run on the efficiency cores).-b -p <pid>
: Downgrades an existing process to run in the background.- -B -p <pid>: Removes the specified process from running in the background. On Apple silicon Macs, the process may now run on the efficiency or performance cores. Note that this only works on processes that have been downgraded to the background, and not processes that started in the background.
-s <command>
: Starts the given command in the suspended state. This is useful to allow a debugger to attach to the process right at the start of execution.
Speak Up with say
The say
command is a fun one. It uses the built-in text-to-speech engine to read out any text you provide. You can even create an audiobook from a text file with say -f input.txt -o output.aiff
.
$ say <message>
$ say -f <filename to speak> -o <filename to save to>
Flags
-f
: Filename to read.-o
: Audiobook file to create.
Power Management with pmset
The pmset
command is a handy tool that provides control over your Mac’s power management settings. It’s incredibly useful for determining what processes might be preventing your Mac from going to sleep, managing your system’s energy consumption, or tweaking your system’s behavior on battery power. For instance, pmset -g assertions
will show you the processes that are currently preventing your system from sleeping.
$ pmset -g
$ pmset -g assertions
$ pmset -g thermlog
$ pmset displaysleepnow
$ pmset sleepnow
Flags
-g
: Displays all available power configuration information.-g assertions
: Shows information about power-related assertions made by other processes. This can be useful for finding a process that is preventing your Mac from going to sleep.-g thermlog
: Displays information about any processes that have been throttled (useful when running benchmarks).displaysleepnow
: Puts the display to sleep without putting the the system to sleep.sleepnow
: Puts the entire system to sleep.
Mastering Quick Look with qlmanage
The qlmanage
command lets you interact with Quick Look, macOS’s built-in tool for previewing files. Here’s how you can use it:
$ qlmanage -p <file>
$ qlmanage -m
$ qlmanage -r
$ qlmanage -r cache
Flags
-p <file>
: Opens a Quick Look preview window for the given file.-m
: Displays status information about the Quick Look server process.-r
: Restarts the Quick Look server process.-r cache
: Resets the Quick Look thumbnail cache.
Manage OS Updates with softwareupdate
One of the greatest conveniences of macOS is the softwareupdate
command. It allows you to manage your operating system updates directly from the terminal, giving you full control over when and how updates are installed.
$ softwareupdate --list
$ sudo softwareupdate -ia
$ softwareupdate --fetch-full-installer --full-installer-version <version>
Flags
--list
: Prints out a list of all available software updates.-ia
: Installs all available updates.--fetch-full-installer --full-installer-version <version>
: Tries to download the full installer of the specified macOS version to /Applications.
System Sneak-Peek with system_profiler
As web developers, it’s essential to have an in-depth understanding of our machines’ capabilities. system_profiler
is a macOS command that provides you with comprehensive system information. It can be a little overwhelming at first because it prints all available system information by default. But fear not, we can break it down!
$ system_profiler
$ system_profiler <datatype>
$ system_profiler -listDataTypes
$ system_profiler SPHardwareDataType
$ system_profiler SPSoftwareDataType
$ system_profiler SPPowerDataType
$ system_profiler SPDeveloperToolsDataType
Flags
<datatype>
: Only prints information about the given sub-system.-listDataTypes
: Lists all available sub-systems to get information from.SPHardwareDataType
: Prints an overview of the hardware of the current machine, including its model name and serial number.SPSoftwareDataType
: Prints an overview of the software of the current machine, including the exact macOS version number.SPPowerDataType
: Prints power and battery information, including the current AC wattage and battery cycle count.SPDeveloperToolsDataType
: Prints the currently active version of the Xcode developer tools and SDK.
Wrapping Up
And there you have it, folks! A nifty little guide for all my fellow web developers to level up your Mac terminal game. We’ve dived into the vast ocean of Mac terminal commands and come back up with some real pearls. From keeping your Mac awake with caffeinate
to conducting a Spotlight search with mdfind
, the power of your Mac terminal is just a command away.
So, the next time you find yourself reaching for your mouse, remember that your keyboard can often get you there faster. It’s all about knowing your Mac terminal commands. May your code run error-free, your coffee cup never empty, and your terminal commands always be at your fingertips.
Share Your Thoughts