Mac Terminal

...

cd

change directory

Enter, cd followed by the directory you would like to access.

Examples:

cd documents
cd desktop

cd ..

change directory ..

This will back you out of the current directory to its parent directory.

Example:

Let's say you are currently in:
desktop > folder

enter cd .. in the terminal to get to your desktop

cd -

change directory -

Return to the directory you were just in.

Example:

Let's say you were just in:
desktop > folder

and you are currently in:
desktop

enter cd - in the terminal to return to:
desktop > folder

cd ~

change directory ~

Brings you back to the home directory.

Example:

Let's say you are in:
Users > myuser > desktop > folder

enter cd ~ in the terminal to return to:
Users > myuser

pwd

print working directory

This command will return to you the path of the current directory/file you are in.

Example:

Let's say you are in:
desktop > folder

enter pwd

to return something like:
Users/myuser/desktop/folder

ls

list

This command will list the contents of the folder/directory you are currently in.

Example:

Let's say you are in:
desktop > folder

enter ls

to return a list of the 'folder' contents:
400.shtml img 401.shtml browserconfig.xml index.html contact.html js 500.php robots.txt 500.shtml favicon.ico fonts apple-touch-icon.png humans.txt

ls -l

list -l

This command will list the contents of the folder/directory you are currently in list form.

Example:

Let's say you are in:
desktop > folder

enter ls -l

to return a list of the 'folder' contents:
desktop > folder

enter ls

to return a list of the 'folder' contents:
400.shtml
img
401.shtml
browserconfig.xml
index.html
contact.html
js
500.php
robots.txt
500.shtml
favicon.ico
fonts
apple-touch-icon.png
humans.txt

ls -l

list -l

This command will list the contents of the folder/directory you are currently in, in list form.

Example:

Let's say you are in:
desktop > folder

enter ls -l

to return a list of the 'folder' contents:
desktop > folder

enter ls

to return a list of the 'folder' contents:
400.shtml
img
401.shtml
browserconfig.xml
index.html
contact.html
js
500.php
robots.txt
500.shtml
favicon.ico
fonts
apple-touch-icon.png
humans.txt

ls -a

list -a

This command will list the contents of the folder/directory you are currently in, including hidden ones that start with a period.

ls -la

list -la

This command combines the above two comannds (ls -l & ls-a). This will list the contents of the folder/directory you are currently in, in list form and including hidden ones that start with a period.

open .

open .

This command will the directory you are currently in, in the finder.

open -e

open -e

This command will open the specified file with TextEdit (the native Mac text editing application).

open -t

open -t

This command will open the specified file with the default text editor (if different than TextEdit, which is the native Mac text editing application).

open -a

open -a

This command will open the application you specifiy. If the application name has spaces in it, see the below example.

Example:

/Users/myuser/Applications/Adobe\ Adobe Illustrator 2020\ Adobe Illustrator 2020.app

ping

ping

Run to ping a website from your computer. Do this to ensure a website is up and running.

to cancel: control + c

Example:

/Users/myuser/Applications/Adobe\ Adobe Illustrator 2020\ Adobe Illustrator 2020.app

^c

cancel

Run to make the terminal stop pinging or running what is currently pinging or running.

whois

whois

Run to view the registration details of a domain.

Example:

whois website.com

mkdir

make directory

Run to make a new directory/folder.

Example:

mkdir newDirectoryName

rmdir

remove directory

Run to remove an empty directory.

rm -r

removedirectory & contents

Run to remove a directory and its contents

Example:

rm -r directoryFileName

rm -Rf

remove specific files

Run to delete specific files.

You must include the file path, if you are unsre of the path you can drag the file into the terminal and it will automatically sense its path. Once you hit enter the file is GONE.

Example:

rm -Rf /path/to/file

mkfile

make a file & specified size

Run to create an empty file of a particular size for testing network speeds.

Example:

mkfile 1g test.txt

b = bytes
k = kilobytes
m = megabytes
g = gigabytes

touch

create new file

Run to create a new file, remember to include the file name and the proper file extension.

Example:

touch fileName.txt

man cd

manual page

Run to read the manual page for most commands.

⌘k

command + k

Run to clear your terminal.

date

today's date

Run to return today's date.

cal

Shows specified calendar year

Run to show the callendar for the year specified.

Example:

cal 2020

say

make computer 'talk'

Procede copy with 'say' to prompt your mac to speak out loud in its native voice.

Example:

say good morning

sudo

"superuser do"

Proceed a command with this and you grant yourself admin rights over everything on your computer.

sudo fs_usage

returns processes

Run to return a constant stream of the information as processes are accessing your disk.

to cancel: control + c

!!

repeat command

Run to run the previous command again.

sudo!!

repeat command

Run to run the previous command again.

cat

open unknown file formats

Run when you do not know the format of a file. Use this to investigate it. No matter the file type, this will open it, likely in 'gibberish' but useful when trying to recover a corrupt document.

Example:

cat /path/to/file

ditto -v

copy working file to new location

Run to copy your 'working' folder to a new location.

Adding the '-v' prints the line to the terminal for every file being copied as it is completed.

Example:

ditto -v /old/working/ /new/working/

history

list of commands used

Run to see a list of all the commands you have entered within the terminal so you can go back and see what you have run.

uptime

display time and running time of mac

Run to display the current time and how long your mac has been running.

caffeinate

prevents sleep mode

Prevents the mac from going to sleep.

to cancel: control + c

caffeinate -u -t

prevents sleep mode

Run to prevent sleep for a specific amount of time.

Example:

caffeinate -u -t 600

The number represents the number of seconds the mac will prevent sleep, 600 prevents sleep for 10 minutes.