Mac Unix

Set up your programming environment


Must have for your Mac

Get homebrew – no longer drag an icon to install

Homebrew – “the missing package manager for macOS” will make it so much easier to download, upgrade and maintain your packages. It will install packages super transparently in /usr/local/Cellar/* and symlink commands to /bin.

Must have for node.js


a version manager for node. You will likely use many different node versions if you are pulling down different production repos, nvm will help you install and switch the the correct versions.


use nvm to install the latest version of node.js

$ nvm install node


TODO rust, iOS, python, scala, screen sharing

Mac Unix

How to protect your files from deletion

I wrote about this before, but its important enough to write twice

How to revoke write permissions to a directory

How to revoke your own user permissions 

$ chmod u-w dirname

How to delete all permissions from anyone on your system 

$ chmod a-w dirname

removing write access on a file does not stop it from being removed,

you must remove write access to the directory to protect the file from deletion – Ice Bear

How to test this

To test this, simple change the permissions and try to $ rm any_file_name. You can even rmdir dirnameand it will protect the directory from deletion

Mac Unix

Intro to OSX File Management Commands

Filenames can have spaces!

So when you deal with them either surround the filename with apostrophes like this: "my file name.txt" or escape the spaces my\ file\ name.txt. Otherwise, don’t create new file names with spaces or escape characters to keep your sanity.


* greedy wildcard

? single character wildcard

[] single character list of wildcards

{} pattern list of wildcards

Say you have files:

kale1.txt, kale1a.txt, kale2.txt, kale2a.txt, kale3a.kale

$ ls kale?.txt – would match kale1.txt, kale2.txt

$ ls kale[1-3].txt – would match kale1.txt, kale2.txt

$ ls kale[1-3].txt – would match kale1.txt, kale2.txt

$ ls kale{2, 2a}.txt – would match kale2.txt, kale2a.txt

$ ls *.txt – would match all the txt files

$mv *.kale Kale\ Files – would move all .kale files to another directory

reading files and finding within files – cat, less, grep

cat – reading files

you can cat multiple files and even cat multiple files and pipe them into another

$ cat file1.txt file2.txt > files3.txt

less – reading files in a scrollable way

less is actually more, more is actually less! Note how this two executables are the exact same size!

$ ls -l /usr/bin/{more,less}

How to make less more bearable

$ less -M filename – the M flag will show you where you are in the file and what percentage you are in.

During less:

Space – advance to the next page

b – advance back one page

v – starts vim

g – goes to beginning of file

G – goes to end of file

/word searches forward for a word

?word searches backwards for a word

grep – finding within files

grep uses a different, more sophisticated regular expressions system then the wildcards from above

$ grep secrets *.txt – searches for the text “secrets” in all the .txt files

moving and copying files with wildcards!

mkdir – making directories

mkdir takes wildcards! So if you wanted to make a different directory for the next three years, try:

$ mkdir taxes20{18,19,20}

cp – copying

cp takes wildcards! So if you wanted to move those new directories into a sub directory

$ touch taxes20{18,19,20}.txt # creates these files
$ cp taxes20{18,19,20}.txt ./taxes # copies those files into a new “taxes” directory

mv – moving

more wildcards!

$ mv -i taxes20{18,19,20}.txt ./my_taxes # moves those files into a new “my_taxes” directory interactively

rm – removing

$ rm -i .[^.]* removes all hidden files (., ..)

$ rm -i taxes*.txt removes all files with that wildcard


gzip for single files

$ ls -l to check the size of the file you are going to compress

Then use $ gzip -v to compress (verbose), $ gunzip -v to uncompress (verbose)

tar for directories, tar+gzip for the ultimate combo

$ du -s Kale\ Recipes to check the size in 512 byte blocks

$ tar -czvf my_kale_recipes.tgz "Kale Recipes" – to compress

$ tar -xvzf my_kale_recipes.tgz – to uncompress


-c is to designate you are creating an archive

-x is to designate you are extracting an archive

-z is for using gzip,

-v is for verbose,

-f is to designate you are providing a filename

.tgz is the file extension for tarballs that are gzipped, sometimes you will see .tar.gz

Mac Unix

Intro to your OS X Filesystem and Permissions

How to find home

note: as a user of the system you will be given a user directory under the Users directory

$ echo $HOME

How to go to the home directory choices:

$ cd $HOME$ cd ~$ cd, and

$ cd then drag your home directory from your Finder window

How to go to the root directory

note: when you see pathnames as such Users/patrick/Documents, this is an “absolute” path name starting at the root

$ cd /

How to print your working/current directory

note: every terminal window operates an independent working directory

$ pwd

How to list your files

$ ls

$ ls -F – this will append a forward slash (/) to directories, an asterisk (*) to executables or scripts, an (@) to symbolic links

$ ls -al – this will show the “long” version of “all” files in the directory

file permissions are shown on the first column in a super cryptic way like this (feel free to skip this portion: 


these are:

file type (1 char) – here “d” is directory, “-” would’ve meant file

owners file permission (3 char) – the owner has read, write, executable permissions on this directory

group file permission (3 char) – everyone in this users group has read and executable permissions

others file permission (3 char) – everyone on the computer in any group has read and execute permissions

How to see the disk usage of:

$ du Documents/Outline.doc (size of a file in 512-byte blocks)

$ du -s Documents (summary size of the directory in 512 byte blocks)

$ du -sh Documents (summary size of the directory in human readable format)

How to see the remaining free disk space

$ df -H (human readable disk free space using base 10 to calculate sizes)

How to change the permissions on files and directories

$ chmod "categories" "add/subtract" "permissions" "filename"

The categories permission options are:

u  owner, g  groups, o others, and

a – all permissions, owner, groups and others

The add/subtract options are:

+  adding, -  subtracting

The permission options are:

r  read, w  write, x  execute


How to delete your user permission from removing the files within a directory (write access)

$ chmod u-w dirname

How to delete all permissions from removing the files within a directory (write access)

$ chmod a-w dirname

removing write access on a file does not stop it from being removed, you must remove write access to the directory to protect the file from deletion – Ice Bear

How to change the owner of a file or directory

$ chown some_name filename


Part II – Intro to OSX file management

Mac Unix

Mac Unix Command Basics for Beginners

These are useful unix commands that are entered through a Terminal shell prompt. These commands are actually names of Unix programs that usually sit in a folder called /bin

where am i? pwd

How to check the current directory $ pwd

learn more about anything – man

How to bring up the manual page for a command: $ man ls or $ man pwd

go somewhere –  cd

How to go to user root:  simply $ cd

How to go to root: $ cd ~ or $ cd /

list things ls

How to list files: $ ls

How to list files, one per line: $ ls -a1 (thats a one)

How to list hidden files also: $ ls -a

How to list only hidden files: $ ls -d .?*

How to list files in some other directory: $ ls /path/to/directory

reading a file cat

How to read a file to terminal: $ cat filename

copy things cp

How to copy a file: $ cp target_file copied_file

How to copy a directory: $ cp -R original_directory copied_directory

How to copy a directory contents into the current directory

$ cp -R original_directory/ .

remove/delete things rm

*** WARNING this bypasses the Trash bin and things cannot be undeleted ***

How to delete a file: $ rm target_file

How to carefully delete a directory: $ rm -r target_directory

How to FORCE delete a directory: $ rm -rf target_directory

open chrome (open)

open /Applications/Google\

open /Applications/<Tab><Tab> (to get a list of available options)

abort the current command (Ctrl – C)

delete the everything to the left of the cursor (Ctrl – U)

Basics Plus: bonus section

open files with open

Do you ever download PDFs on Chrome and the browser insists on opening the pdf IN BROWSER?

copy the url path file://path/to/pdf and simply run open on it

$ open file://path/to/pdf

run multiple commands ;

How to clear the screen, print the current working directory, print the date, print the weather from “”


pipe stdout to stdin |

How to pipe the contents of a file (“my_file.txt”) to your system clipboard

cat my_file.txt | pbcopy

pipe stdout ot stdin |

How to pipe the result of ls to vim

ls -1 | vim -

multiline commands \

rm -rf \



Setting up a new computer (Mac – applications)

Change these System Preferences immediately

1  – MAX OUT your Keyboard key repeat and shorten your delay

2 – Change your CAPS LOCK into (^ Control).

Think about it, unless you are constantly yelling on the internet, you never really use CAPS LOCK

Download these Apps

* Alfred

this is so much better than spotlight if not just for the ability to calculate numbers and save it to the clipboard (why does spotlight insist on opening the calculator app). Make sure to override the spotlight shortcut (Command+Space)

* BetterSnapTool – many people use magnet, but this free tool is a good replacement if you want simple window snapping. This program lets you snap a window to just the left or right half, corners or even thirds!

The half shortcut is best on my Macbook Air

I use an amazing programming monitor, Dell UltraSharp U3415W 34-Inch Curved, that is really game changing and it comfortably fits 3 full windows. Instead of having two monitors and a bezel in the middle, using a single monitor helps you never break context by looking from screen to screen.

* Dropbox – there are really VERY few valuable irreplaceable things on your laptop or cellphone. The main one is your personal photos. I’ve had phones stolen and laptops destroyed and when I replace them, I generally have a faster, stronger device but I realized the most important things were missing – memories. Upload your photos. Use any cloud you want.

* iTerm – Benefits are strong. Split panes for multiple terminal instances like shown below are super useful for running jobs.

Tip: “Hot Key” allows you to bring up the terminal window on a shortcut! Only Alfred and terminal should have such an honor. If someone combined the two programs… Set this to Control+Space

Tip: Make sure to change the working directory. You will be opening a lot of tabs, you don’t want to end up at Home

Tip: Turn on “Secure Keyboard Entry” from the iTerm2 menu

iTerm2 -> Secure Keyboard Entry

* RescueTime – this depends on whether you like to self quantify your productivity. The app runs on the background of your computer, constantly pinging to see what apps you are using or which websites you are visiting. With all this data, it puts all your activities into a pie chart and lets you know your productivity score. I find it extremely valuable.


Xcode, Chrome, One Note, Antisleep, Flux

Set up your configuration files

* Updated: added RescueTime; fixed typo


What are the Mac symbols?

Mac Symbols

If you are loyal to your 2013 Macbook Air, here’s the new mac keyboard buttons.

What is the mac symbol for Control?

Control (or Ctrl) ⌃

The Control key was originally responsible for entering control characters (or non-printing characters) in terminal applications. The first mac did not have a control key but it was later added to allow this.

The shortcut in your brain could be to think about how hierarchies usually work, with the control at the top. This symbol is pointing up to the Control. 

What is the mac symbol for Option/Alt?

Option (or Alt) ⌥

The shortcut in your brain can be that the symbol looks like two different paths from the same origin. Two alternative, or two optional paths.

What is the mac symbol for Command?

Command (or Cmd) ⌘

According to wikipedia, Steven Jobs saw too many apple logos on the display of the GUI and decided they needed another symbol as the modifier key. Bitmap artist Susan Kare proposed this symbol for the Nordic countries as an indicator of cultural locations and places of interests.

This one conveniently has

See more at the official Apple docs