Mac OS Commands

Updated: 1 Jan 2024

1. How do I type in commands rather than use Finder?

Mac OS comes with Terminal application which opens a shell windows such as Bash (Bourne Again Shell) or zsh (Z Shell). You can access it via Applications, Tools, Terminal.

The current directory is displayed followed by a flashing underline cursor. To exit this window, type exit, Cmd+Q or click on the X on top left of the window.

You can change the default shell via Terminal preferences, just change the 'Shell opens with' and enter path to the shell program e.g. /bin/zsh, /bin/bash, /bin/sh, /bin/csh, and /bin/ksh.

2. What commands are available to use with Terminal?

Many of the commands are similar to the ones with Unix and Linux. Commands can be run from the current directory or those listed in the command path. The command path can be viewed by typing echo $Path and can be edited via the System Control Panel, Advanced, Environmental Variables. Most commands are available in the /bin, /sbin, /usr/bin and /usr/sbin folders. To view the parameters of the command you can type either man <command> or <command> --version. Commands can be combined using the pipe (|) character e.g. cat file | more.

Applications can be launched from the command line by entering the path to the executable within the application e.g. /Applications/ .

File System Commands Purpose
cd <directory> Change directory. To change drive just enter name of drive letter followed by a colon e.g. C:
cp <source> <dest> Copy one or more files (the ? and * wildcards can be used to select files)
rm <files> Delete one or more files
ls <dir> List files in a directory
mkdir <directory> Make or create a directory
rmdir <directory> Remove or delete a directory
mv <orig> <new> Rename or move file(s)
cat <file> Display contents of a text file
more <file> Display contents of a file a screen at a time
nano or vi <file> Change contents of a file (editor)
grep "string" <file(s)> Search for string in a file
cmp <file1> <file2> Compare two files
zip <file(s)> Compact or compress a file
fsck Check disk for errors
fdisk Disk Partitioning program
sed <file> Line editor (use ? for help)
chmod <perms> <file> Change permissions of file/folder
chown <owner> <file> Take ownership of files or folders
lpr Print files
mount Mount filesystem
pwd Print working directory
Other Commands Purpose
caffinate Prevent system from slooping
csrutil Configure system integrity protection
cron Set up scheduled commands
asr Apple Software Restore
defaults Set preferences, show hidden files
dig DNS lookup
diskutil Disk utility
dscl Directory services client (see article)
dsmemberutil View user and group rights
GetFileInfo Get file attributes
groups List groups a user is in
hdiutil Manipulate ISO disk images
ifconfig Network interface configuration
kextfind List kernel extensions
kextstat Display status of kernel extensions
kextunload Terminate and unload driver instances
launchctl Manage services
mdfind Spotlight search
networksetup Network and system preferences
ntfs.util NTFS file system utility
open Open a file, folder, url or application
osacompile Compile an Applescript
osascript Run an Applescript
pkgutil Query and manipulate installed packages
pmset Power management settings
shutdown Shutdown, restart or logout from PC
say Convert text to audible speech
screencapture Capture screen image to file
scselect Switch between network locations
scutil Manage system configurations
softwareupdate Software update tool
su Substitute user identity (super-user)
sysadminctl Add, update or delete user accounts.
system_profiler Report system configuration
systemsetup Computer and display settings
tmutil Time Machine utility
ufs.util UFS file system utility
Server commands  
apachectl Apache web server control
bootpd BootP and DHCP service

More information about bash commands for Mac OS, visit, the bash command list page or zsh manual.

4. How do I change the colours for the command prompt?

Open a Terminal window, select Preferences, on the Terminal menu. Select Profiles, then you select a theme and change colours for text and the background.

5. How do I change the command prompt text?

By default, the command prompt is the host name , optional current path followed by a $ or % sign e.g. MacBook:~/Desktop Admin %. This is set by the command export PS1='prompt-string'. The prompt string can contain the following special string to display different values: \d = date, \t = time, \h = host name, \# = command number, \u = user name, \W = short working directory, or \w = full working directory. The command can be saved to .bashrc or .bash_profile for future bash sessions.

6. How do I create scripts?

Script files contain a list of commands to perform simple tasks. Use a text editor such as TextEdit or a command line tool like nano or vim to create your scripts.
Once the script is created, you need to make it executable, by setting the 'x' execute flag using chmod command e.g. chmod +x filename.

For a more user friendly method of scripting use the Apple Automator.

7. Where can I find other command line tools?

For more advanced scripting languages try AppleScript, Perl, Python, PHP , Javascript or Java..
Python3 and PHP7 can be installed using Brew or MacPorts.

8. Can I run Microsoft's .NET Framework (PowersShell) or DOS commands?

Yes, Microsoft have released .NET framework for Windows, Mac and Linux. Visit the Net Core site and how to install PowerShell.
For legacy MS-DOS type commands, try DosBox.
For Apple II ProDOS, try the Octalyzer emulator.

Go to Networking