Tecnate | Last Updated: 2024-05-19
- Mac Terminal Cheatsheet
This cheatsheet is for quick reference to common commands for the Mac terminal (with significant carryover to Linux as well).
- Assume Bash/Zsh shells unless specified otherwise.
- Assume that multi-key commands written with the
+symbol are chords (key combinations in sequence). Don't actually type the+sign unless instructed. &&: chains commands together (if the preceding command succeeds).
⌘/Command (Cmd)⌥Option/Alt⌃Control (⌃)- Not
^caret (the "6" key special character on a standard US keyboard)
- Not
⇧Shift↑/↓Up/Down Arrows→/←Right/Left ArrowsEnterEnter/ReturnSpaceSpacebar
There are three main tools to search and process text:
grep: finds text patterns in a file. (Most simple.)sed: finds and modifies data.awk: a programming language. (Most complex.) It is usually used to:- Process field-oriented data.
- Perform numeric comparisons/calculations.
- Modify data based on calculations.
⌃A
⌃E
⌥←
⌥→
All of the following Clear commands will "copy" the cleared text and make it available to yank (paste), except for the ⌃C signal interrupter.
⌃U
⌃K
⌃W
Esc D
⌃L
This clears the terminal screen of text by adding newlines to your window.
⌃Y
The most recently cleared text, regardless of length, is available to be recalled.
⌃C
This terminates execution of the process and wipes the command line regardless of cursor position, but you will only be able to yank (recall/paste) previously cleared text.
mkdir directoryName
-p: the parents option.
Create directories within the current working directory.
mkdir -p dir1 dir2 dir3
Create directories within a specified parent directory.
mkdir -p parentDirectory/dir1 dir2 dir3
mkdir -p county/city/neighborhood/
cp -r sourceFolder destinationFolder
touch fileName.txt
touch file1.txt file2.js file3.jpg file4.html
mkdir folderName && touch folderName/fileName.txt
mv file1.txt file2.js folderName
Executing some commands will require admin (superuser) privileges.
sudo: superuser do.- Requires your system password to execute.
Prepend sudo to any command.
sudo -s
-s: shell.- ⛔️ This option will open a new shell session with superuser privileges so you don't have to prepend everything with
sudo.
- ⛔️ This option will open a new shell session with superuser privileges so you don't have to prepend everything with
Modifying system power will likely require sudo permissions.
Use the following options with any of the shutdown commands below:
-h: halt (shut down/power off)-r: reboot (restart)-s: sleep
sudo shutdown -h now
sudo shutdown -h +10
Use 24-hour (hh:mm) time to schedule a power off.
sudo shutdown -h 22:30
Convert a jpg to png
sips -s format png oldImage.jpg --out newImage.png
Set max height/width to 800 pixels.
sips -Z 800 image.jpg
networkQuality
Convert a text file to HTML
textutil -convert html document.txt
Convert a text file to PDF
textutil -convert pdf document.txt -output document.pdf
say hello world