| Tecnate | Last Updated: 2024-05-19 |
This cheatsheet is for quick reference to common commands for the Mac terminal (with significant carryover to Linux as well).
+ 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 (⌃)
^ caret (the “6” key special character on a standard US keyboard)⇧ Shift↑ / ↓ Up/Down Arrows→ / ← Right/Left ArrowsEnter Enter/ReturnSpace SpacebarThere 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:
⌃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.
Prepend sudo to any command.
sudo -s
-s: shell.
sudo.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: sleepsudo 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