| README.md | ||
Best Practices Computing with a Mac
This is a guide to using one's Mac os system targeted for those who utilize this tool daily. This guide contains information targetting both the advanced user, and those just beginning to learn to maximized the use of their device.
What is computing?
For the purposes of this guide. Computing is simply the act of using a computer to get work done.
Table of Contents
- The Directory
- Level: Beginner
- Answers: Where are files actually located? How does my computer understand my data?
- Skip: Skip this if you are familiar with *nix-like OS file trees
- Basic Concepts
- Level: Beginner
- Answers: What are abstractions? What are the common tools are patterns of thought used in computing? How to find state.
- Skip: Skip this if you have programmed Conway's GoL or equivalent.
- Common Tools
- Level: Intermediate
- Answers: Activity Monitor. Spotlight. Terminal.
- Skip: Skip this if you have written a .bashrc or similar.
- Getting Help
- Level: Beginner
- Answers: How do I learn more? Setting up and using man. Finding answers online.
- Skip: Skip this if you have spent hours on Stack Overflow or in manpages already.
- A Brief History Lesson
- Level: Beginner
- Answers: Why are things all like this?
- Skip: Skip this if you just want to focus on the how and not the why of computing processes.
- The World Wide Wed
- Level: Advanced
- Answers: How the web works. Safely interacting with the web.
- Skip: Skip this if you're familiar with xhr injection and polyglot drivebys.
- Data and how computer's see it
- Level: Intermediate
- Answers: How data is commonly stored. Data storage best practices, common shapes of data. Introduction to SQL Relational Databases
- Skip: Skip this if you can write SQL.
The Directory
All Mac computers contain a file system. File systems or directories are common accross all computer operating systems. The term Directory is a general term for file system like structures in computers. Any tree shaped data structure can be refferred to as a directory, but 'The Directory' is nearly always going to refer to your computer's file system. Macintosh computers, along with the majority of computers follow a file system structure defined in a set of computing standards called POSIX (Portable Operating System Interface) as well as holdovers from Berkeley Software Distribution (BSD), the underlying operating system Apple built Macintosh off of.
So, what is a file system? Your computer devides all the storage on your machine into seperate files. EVERYTHING is a file on a mac system. Your drivers are files, your documents are files, programs are files or collections of files, even folders are a special type of file. These files are organized via a heirarchy starting at a special location called 'root' always represented via a single '/' character.
Below is the top level file structure of a modern Mac. Once upon a time, one could follow along in this tutorial via finder, but since Mac Catalina, Finder no longer shows files in the location that they actually are. Mac claims this is to 'reduce confusion' for users. It's important to remember Mac finder will not show you where your files are actually located even if it can provide easy access to them.
/
├── Applications
├── bin
├── cores
├── dev
├── etc -> private/etc
├── home -> /System/Volumes/Data/home
├── Library
├── opt
├── private
├── sbin
├── System
├── tmp -> private/tmp
├── Users
├── usr
├── var -> private/var
└── Volumes
Note the special '->' symbols beside etc, home, tmp, and var. That is the symbol for a symlink and it is like a forwarding address for a file. It means the file. This is one of those BSD holdovers I mentioned. Symlinks show that despite the folder /tmp/ being located in the top level folder /private a symlink also makes /tmp available at the top level /.
Each of the following folders has a general use that allows one some intuition as to what they contain. Though, it's important to keep in mind, that the underlying APFS Mac uses seperates information physically out into two disks for 'system' and 'data' which is read, and read/write respectively. This means that some folders CANNOT be written too, and that majority of work you'll do will be done in the home/ directory. Files will be the foundational concept we build our understanding of computers around.
Navigating and managing the file system will be gone over in Common Tools.
Basic Concepts
Before we continue I'd like to solidify a few concepts and terms used throughout both this document, and information theory in general.
-
Abstraction: A tool used to simplify a process, usually by grouping processes sematically, or relating processes to an equivalent but simpler model. A good example of an abstracted process is driving your car. You operate a steering wheel, gas pedal, break pedal, and these operate abstracted processeses being gear timing, shaft speed, fuel injection, and the many micro-processes needed to physically cause your vehicle to go. Each input you give to your steering wheel is passed along mechincally to another mechnism that orchestrates a collection of mechanical sub-systems that move the wheels, axels, etc.
-
Arguments: You'll often see the use of arguments or variables in computing. Both words refer to the same concept. Computing is rarely about solving one instance of a problem. It's about describing a process that works for an entire class of inputs. Algebraic representations will be common such as
open [file]where open is a command and will be typed every time, and [file] is the variable representing a class of specific inputs. Whereas a specic instance of using open, would beopen https://edenfoods.comto open said website via the default browser. -
Computer Object: Often just
object. This is a concept in computing representing any grouping of data and procedures under a single understood namespace or symbol. This is a wordy way to say, any 'thing' inside a computer. The operating system, files, progrades, functions in programs, inputs given to programs, apps, pictures, packets, cookies, numbers. These are all examples of computer objects. Combining raw data with procedures is the primary tool used to create all programs. One can think of all computer programs as collections of objects performing a procedure (or play). A program is always a computer object itself. -
Equivalency: Equivalence is the categorical act of ignoring trivial differences. Trivial differences are those that do not affect behavior, meaning, or properties we care about. Two things are equivalent when they 'map' or 'evaluate' to the same result under the rules of the system being considered. Sometimes this is called isomorphism. The relationship of equivalence is also often referred to as 'having the sane shape' or 'symmetry' with another object. This concept is far more simple than it sounds when formalized. In as little words as possible, computer objects are equivalent when we can treat them the same.
-
Function: This can refer to a lot of specifc things in computing, but generally it's any process that takes an input (Confusingly including the input of no input, sometimes called the void input) and produces an output. All programs are functions in this loose sense. Program, function, process, and procedure can be used rather interchangably and all generally mean this simple concept of, ƒ(input-value, state) = (output, new-state). This is NOT to be confused with the mathimatical definition of function which states every input can ONLY have ONE output. In computer land this is called a mapping, or just map. There is a special kind of function, we'll often talk about, called a "black box" function. This is any function in which operations in a manner you don't understand. Handling black box functions and verifying them is a common problem that faces one doing computing.
-
Shapes: A more abstracted concept than the previous mentioned. Shapes refer to the patterns made when you graph a function. The shapes you're surely familiar with, (Triangles, squares, etc.) are anagolous to certain processes in computing, and the relations between shapes (e.g. symmetry) are useful models for comparing computer objects. Id est, all computer objects are on some level binary numbers and therefore can be plotted on a graph in which one can visually compare the "shapes" made on the graphes. There are many ways to convert or map a computer object to a shape on a graph, so objects don't have cannonical shapes, but that isn't important to use the concepts of group theory on such objects anyways since the specifics of the mapping is trivial. If you feel you understand function and equivalancy, you understand shapes as well. It is just the logical extenstion of these two concepts.
-
String: A sequence of data. Usually text, but not always. Literally meant to invoke the thought of beads on a string. It's any collection of values who's order in which they are given is important. Note that all text is a string, as if I gave you the order of the letters in this sentance randomly, the sentance would loose its meaning. More formally, a string is a finite stream of self similar values who's ordering is significant.
-
Integer: A set of numbers. Exactly like the math folk say. (-∞, ..., -2, -1, 0, 1, 2, ..., ∞) All the Real numbers, zero, and the real numbers times -1.
-
Float: Numbers that have decimal in them.
-
Technical Debt: Tech debt is an incredibly important concept, explaining whenever someone takes an action on the computer that saves them time in the present, but will create issues that will burn yours or others time in the future. Usually with time interest (Tech debt that does not create problems that take longer to solve than the original can be considered free and need not be worried significantly worried about). Technical debt is a fancy way of saying cutting corners. Tech debt should ONLY be created if the CREATOR of the tech debt has a plan to pay the tech debt BEFORE time interest reaches anyone who did not take out the tech debt. One should try to avoid taking out tech debt, but due to the sheer amount of tech debt acrued by the IT industry as a whole, will require you to take out more to get many processes done. (Id est, The issues of computers not connecting to an ERP server, running out of space, and running out of resources is all solved by an Operating system called plan9. But Mac started with BSD and has acrued too much tech debt in it, to be able to switch to a system that came out after BSD so we're stuck with the problems created by System V Unix). The majority of computer processes today are paying tech debt accrued by the industry in the 80s and 90s. Whenever you 'can't connect' to a resource on the network, you are paying tech debt that was taken out in the late 90s when the industry did not move to plan9 over system 5. This SHOULD upset you.
Common Tools
These tools are fundamental to managing your computer. I've left out the browser as it'll be mentioned in World Wide Web.
Migration Strategy
Perhaps the most important concenpt given here. A migration strategy is the first step to using any tool on a computer. Tools are transiant and there's no garuntee anything you begin to use will work the same way tomorrow. It simply doesn't have to, and many fall into a false sense of security in their tools, because these tools have not changed much. You NEED to define what tools you can move to and how you will do such BEFORE you begin to start using any new tool on a computer. Failure to do this is tech debt and you should expect ignoring the formulation of a migration strategy to cost you significant time in the future.
Spotlight
This is a computer search tool built into your mac. It's not as powerful as grep and find but will locate easy to surface files and data in your filesystem. You can also use it to open programs not on your toolbar/dock. You can access spotlight via the keys, [command]+[space]
Activity Monitor
This program allows you to monitor the other programs that are running on your system. It is incredibly powerful, allowing you to gother nearly all the information the system collects on the running program. This allows you to rapidly diagnosis if your computer or a program is not working.
Terminal
This is a text based way to interact with your computer, giving you greater control than many other user interfaces. (Though sometimes this control comes at the cost of speed and extra verbosity). It allows you to both give your computer commands as well as build lists of commands that can be run together as a program. Programs are repeated sets of commands allowing one to automate any repetitive computer task.
The following entries are all simple programs, called commands in the terminal. Mac terminals use an interpreter called z-shell by default. However, z-shell will by default interpret programs as if it were Bourne Again shell which is defaulted into POSIX compliant mode. Shell is just bash run in POSIX mode.
You will also see exampls written under each command in the following format.
command [options] --argument1-- --argument2--
In the terminal you can hit the tab key to 'autocomplete' the current word you are typing. Autocompletes usually default to paths, and this autocomplete feature is what allows terminal commands to be used in a fast and effecient manner. It's rare you should ever need to type more than the first 3 letters of any word in a command.
man
Your computer's manual. The majority of programs come with a manual. (And I'd think twice about using one in which the devs didn't take the time to write a manual. It's a very good first sign that a piece of software is of poor quality.) Man is uaully bundled with a search funtion called apropos and whatis as well.
To use:
man [command to lookup]
apropos [search term]
Example:
man man <- Read the manual manual.
man zsh <- Read the Z-Shell manual.
I suggest running man [commandname] for each of the commands gone over in this document.
pwd
Print Working Directory. This command shows the current working directory. The current working directory, is the folder you are currently located inside in the terminal. This defauls to a place called, HOME.
Usage:
pwd
ls
This command lists files in the current working directoy. You can add the options, a to show hidden files. More options are available and are explained via man.
Usage:
ls <- Show files at current working directoty
ls -lah <- Show all files in a list with human readable file sizes.
ls ~/Downloads <- Show the files listed in my downloads folder.
cd
Change Directory. This command changes the current working directory to whatever is given to it. Use tab complete to avoid spelling errors and to reduce typing.
cd [new-directory]
cd ~/ <- Change to your HOME directory.
cd .. <- Go up one folder.
cd ../Downloads/ <- Move up one folder, and then down into the folder, /Downloads/
mv
Move. Move a file from one location to the other. This is the same as copying a file, and then deleting it. This is also how renaming a file works. (A file is never truly moved in the physical sense when it is on the same physical disk, mv really just changes the file's metadata location.)
mv [sourcefile] [destination]
cp
Copy. This copies a file from one destination to another.
cp [sourcefile] [destination]
rm
Remove. Deletes a file, use -r to delete directories as well.
rm [file to delete]
rm -r [directory to delete]/
file
File. Shows what kind of file a file is.
file [file to investigate]
find
Find. Searches for files and directories that match a given name or other criteria, starting from a specified location. By default, it searches the current directory and all of its subdirectories.
find [starting-directory] [search-options]
find . -name "notes.txt" <- Find a file named notes.txt in the current directory and all subdirectories.
find ~/Documents -name "*.pdf" <- Find all PDF files in the Documents folder.
find . -type d <- Find only directories. (-type f finds only regular files.)
grep
Global Regular Expression Print. Searches through a file (or files) for lines containing a given word or pattern, and prints the matching lines.
grep [pattern] [file]
grep "hello" notes.txt <- Find every line in notes.txt containing the word hello.
grep -i "error" log.txt <- Find lines containing error, ignoring uppercase/lowercase differences.
grep -r "TODO" . <- Search recursively through the current directory for lines containing TODO.
less
Less is the classic document viewer for the terminal. It still surpasses other document views in the processing of large files that don't completely fit into memory. When other document viewers fail, less won't.
less [filename]
sh
Shell. Starts a new shell (command interpreter), allowing you to run commands or execute a shell script. On modern macOS and Linux systems, sh is usually a compatibility shell that behaves like the traditional Unix shell.
sh <- Start a new shell session. Type exit to return to the previous shell.
sh [script.sh]
sh install.sh <- Run the shell script install.sh.
sh -c "echo Hello" <- Run a single command in a new shell.
Document Editors
Not all document editors are created equal. There are lots of different editors, and choosing one to learn is certainly one of the ways to significantly boost your ability to use a computer. Most are familiar with a class of these programs called Word Processors. Microsoft Word being the most common of these. Some are designed only for specific documents, such as excel. These can have some use, but learning any document editor takes time so spending time to work on only a single document type, when many document editors give a more robust toolset. Document editors can be devided into three general groups.