Your Mac: really useful macOS terminal commands Your Mac: really useful macOS terminal commands

You may have heard that macOS is a Linux-based operating system. This is not true. The two are related, though: both are Unix-like, but their kernels are distinctly different. macOS, if you’re interested, is built on the Darwin kernel, a derivative of BSD Unix, while Linux uses its own independent kernel.

The origins of both operating systems mean they have at least one thing in common: terminal. Windows has one, too, but it’s actually a different matter, a host application that supports various shells (Command Prompt, PowerShell). In macOS and Linux, the terminal is deeply integrated into the system and has direct access to its core functionalities. This means that you can do a lot using the commands.

This piece is sort of a cheat sheet that gives you macOS terminal commands that are handy in the life of a regular user, complete with examples where necessary. Share and bookmark for future reference!

First things first: you can always summon help in the terminal by putting man before the command or -h after it. For example, man top will give you options of this command that cater to more specific needs. Largely the same goes for top -h.

macOS system and process-related terminal commands

These are probably the most useful commands on this list, since it is typically faster to execute one of them than make several steps to reach a menu that gives you the respective info and allows doing similar things.

---

top – shows system processes and resource usage, real-time data. Useful when you feel something’s off about the performance of your Mac (same as most of the commands in this section). The command with some useful modifiers:

  • top -o cpu – sort by CPU usage;
  • top -o rsize – sort by memory usage;

---

ps – lists running processes and some info about them, including PIDs, or process IDs, which you need to know to kill a process. The most useful option of this command is ps aux as it yields a detailed process list with CPU and memory usage.

---

kill – terminates a process by its PID; example: kill 234235. You can also use a name associated with the process to be killed, like killall Safari.

---

df -h – shows how the disk is used with data shown in an understandable format.

---

diskutil list – show detailed info about disks and volumes.

---

uptime – shows how long the system has been running.

---

whoami – in case you forgot what username you are logged in under.

macOS administrative and power terminal commands

These commands are also handy in many situations.

---

sudo – this is a prefix to a command you want to execute as a superuser. 

---

sudo shutdown -r now – restarts the system without delay or unnecessary questions.

Common options:

  • sudo shutdown -h now – shutdown immediately;
  • sudo shutdown -r now – restart immediately;
  • sudo shutdown -s now – sleep immediately;
  • sudo shutdown -h +10 – shutdown in 10 minutes.

---

sudo purge – this command frees inactive RAM (that which was previously used by apps and still allocated for them) into "free" memory and flushes disk and memory caches. Your machine starts feeling fresh, as if after a reboot, but whatever you have opened remains that way.

---

chmod – changes permissions of a file/directory.

Example: chmod 755 thisfile.txt – grants the owner of thisfile.txt read, write, and execute permissions, while everyone else gets to read and execute it only.

---

caffeinate – prevents the Mac from falling asleep. Run without modifiers, it keeps the system up until disabled manually. Can be used to allow a process to complete, for example: caffeinate -w 1552, where 1552 is the PID.

macOS terminal navigation, folder, and file commands

These are probably not used as often as other commands on this list: Finder is great (check out our post “Finder for macOS: popular and less known features”), and there are third-party file managers that chime in where it’s lacking. But it still is nice to know them, at least for the sake of that nice feeling of being a more advanced user than the next guy.

---

cd – change directory, i.e., navigate to a specific folder.

Commonly used options:

  • cd ~/Documents – go to the Documents folder in the home directory.
  • cd / – go to the root directory.
  • cd .. – go up one directory level.

---

ls -lah – list files and directories. You can go with just ls, but this one gives you the contents of a folder you’re in now as a detailed list that includes hidden files and provides file sizes in a human-readable form.

---

pwd – print working directory, i.e., show where you are now.

---

mkdir – make a new directory. Example: mkdir new_folder

---

rm – the remove command. Options:

  • rm file.txt – remove file.txt (replace “file.txt” with the name of the file you want to remove)
  • rm -r folder_name – remove a directory and its contents recursively.
  • rm -rf folder_name – force remove a directory and all contents without asking for anything in the process.

---

cp – the copy command. Lets you copy files or directories. 

Options: 

cp file.txt ~/Documents/ – copies “file.txt” to the Documents directory.

cp -r some_folder ~/Documents/ – copies “some_folder” to the Documents directory.

Note the -r in the directory copying command. The copying is done recursively.

---

ditto – copy directory contents preserving metadata. Example: ditto some_folder ~/Backup/ – copies “some_folder” and everything inside without changing the metadata to the Backup folder.

---

mv – this one lets you move files or directories and rename files. Here’s how it works:

  • mv some_file.txt ~/Documents/ – moves “some_file.txt” to the Documents directory.
  • mv some_file.txt other_file.txt – rename “some_file.txt” to “other_file.txt.”
  • mv some_folder ~/Documents/ – moves “some_folder” to the Documents directory.

---

open – open a file or a folder using the default macOS application. Example: open thisfile.pdf.

open . – opens the current folder in Finder.

---

nano – open a file in Nano, the simple terminal text editor. Example: nano justatextfile.txt

There you have it, the macOS terminal commands that are, depending on what you do with your Mac, will be coming in handy on a more or less regular basis. And in case you want more control over what’s going on under the hood of your favorite computer, browse the System Tools section of our catalog:

Mac Informer – System Tools

Author's other posts

Microsoft adds scareware detector to Edge; what about other browsers?
Article
Microsoft adds scareware detector to Edge; what about other browsers?
Edge's brand new AI-powered scareware detector blocks those scare-inducing pop-ups and keeps you safe. Other browsers offer assistance, too.
Apple plans to sell a cheaper MacBook: what is it going to be?
Article
Apple plans to sell a cheaper MacBook: what is it going to be?
Apple's affordable MacBook with a 6-core A18 Pro chip, 8GB RAM, and ~12.9" LCD display is set to launch in 2026. Targeting students, it may start at $599.
Windows 11 23H2 support ends in November; how to upgrade to 25H2?
Article
Windows 11 23H2 support ends in November; how to upgrade to 25H2?
Windows 11 23H2 will soon join Windows 10 in the list of no-longer-supported versions. Here is what you can do about it.
AI browsers: the common features that really help
Article
AI browsers: the common features that really help
What AI-powered browsers of today actually offer? Here is a no-nonsense list of features they are actually capable of.