Command line, terminal, shell, CLI ("command line interpreter" or "command line interface").
- It helps make some things faster
- There are tools that only exist for the CLI and don't have a point-and-click interface.
- It opens the door to programming languages like Ruby
Mac: Open the Terminal app. (It's inside Applications->Utilities, but you can also get to it by searching.)
Windows: Press the Windows key and search for PowerShell. You can also press Windows-R to get the "run" menu and type in cmd, then press enter.
When you use the Finder or File Explorer, your window is always open to a specific folder. You can go to other folders by clicking on them. Similarly, a terminal is always in a specific folder. Instead of clicking, you use text commands to figure out where you are and to move around.
By default, the terminal starts in your home directory.
| Mac | Windows | Description | 
|---|---|---|
| pwd | pwd | shows you what directory you're in (and the full path to that place) | 
| ls | ls | shows you a list of all things in current directory | 
| cd Desktop | cd Desktop | moves to the Desktopdirectory inside the current directory | 
| cd / | cd C:\ | moves to the "top" of your hard drive | 
| cd /Users | cd C:\Users | moves to the folder called Users(if there is one) in your hard drive | 
| cd ~ | cd %HOME% | moves back to your home directory | 
The thing after the cd is an "argument" -- it's something you give to the cd command to do whatever it is the command does. cd moves the terminal "into" another folder, like double-clicking in Finder or File Explorer.
(On Windows, doing cd without an argument simply shows you the current directory, like Mac pwd. On Mac, doing cd without an argument moves to your home directory.)
- Relative paths: you can get into Desktopfrom your home directory by doingcd Desktop, becauseDesktopis inside your home directory. Similar to the way the<link href="...">tag works when something is in the same directory.
- Absolute paths: you can get into Desktopdirectly from anywhere by entering in the absolute path or full path of the Desktop foldercd /Users/mtigas/Desktop(Mac) orcd C:\Users\mtigas\Desktop(Windows). See thepwd/echo %cd%command to see the current absolute path.
Common path & file aliases
| alias | description | 
|---|---|
| ~(Mac) or%HOME%(Windows) | your home directory | 
| . | the current directory | 
| .. | the directory above this one | 
| * | all files and directories inside this directory | 
| *.html | all files with names that end with .htmlinside this directory | 
Tip: If you mistype and want to cancel the current line you're in the middle of, press Control-C.
Example: From a newly-opened terminal, try the following.
- ls
- cd Documents
- pwd
- ls
Exercise:
- Move into the GitHubdirectory on your computer that was created by the GitHub Desktop app yesterday.- On Mac it's in your home directory; on Windows, it's inside Documentsin your home directory.
 
- On Mac it's in your home directory; on Windows, it's inside 
- Move into one of the repo directories, like awesome-projectorhello-propubdataand get a list of what's inside that directory.
- Use Finder or File Explorer to look at that directory. Are there any differences between what's listed in the user interface vs in the command line?
| Mac | Windows PowerShell | Description | 
|---|---|---|
| mv index.html something.html | mv index.html something.html | renames index.htmltosomething.html | 
| cp index.html index-backup.html | cp index.html index-backup.html | makes a copy of index.htmlto a new file calledindex-backup.html | 
| rm something.txt | rm something.txt | deletes the file called something.txtin the current directory | 
| mkdir MyFolder | mkdir MyFolder | creates a directory named MyFolderinside the current directory | 
| cp -r MyFolder MyFolderCopy | cp MyFolder MyFolderCopy | makes a copy of the directory MyFolderto a new file calledMyFolderCopy | 
| rm -fr MyFolder | rm MyFolder | deletes the directory named MyFolder | 
| Mac | Windows | Description | 
|---|---|---|
| find . | dir -r | shows you all the files and folders in the current directory, and all the files and folders inside all those folders and so on | 
| open . | explorer . | opens a Finder or File Explorer to the current directory | 
| open some_file.txt | explorer some_file.txt | this does the same as double-clicking on some_file.txtif you were in a Finder or File Explorer | 
| subl some_file.txt‡ | subl some_file.txt‡‡ | opens up some_file.txtin Sublime Text | 
| subl .‡ | subl .‡‡ | opens up Sublime Text with this folder in the sidebar | 
- ‡ You need to run this command first:
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
- ‡‡ Not installed in Windows by default; involves editing some settings to turn it on.
| Mac | Windows | Description | 
|---|---|---|
| grep "<p>" index.html | select-string "<p>" index.html | shows you all lines that contain <p>inside theindex.htmlfile in the current directory | 
| grep "text" * | select-string "text" * | look for text in all files in the current directory | 
| grep -r "text" . | --- | look for text in all files inside the current directory and all directories underneath | 
Most commands can give you information on how to use them. Usually you get it by doing -h or --help or /? or /help.
The following lists some information on how to use the git command-line command:
git --help
You should get something like:
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]
...
If a command seems stuck, you can press "Control-C" on your keyboard to cancel it.
If you only pass the first argument to grep or find, for example, it waits for some input instead of searching files in your directory...
# mac
grep "text"
# windows
find "text"
...a you'll need to press Control-C to quit the command.
The modern command line has an autocomplete feature which can help you quickly enter in commands, file names, and directory names.
Try it! From a fresh terminal, type cd Desk and press the tab key; the remaining letters in Desktop should automatically appear.
If your keyboard has "home" and "end" keys, those will go to the start or end of the line, like in Word or other text editors.
Otherwise:
- Control-Awill jump the cursor to the start of the line.
- Control-Ewill jump the cursor to the end of the line.
Helpful if you've mistyped the beginning of a command.
The say command is fun: say hello
Sometimes you need to install software from within a command-line. If it doesn't work normally, you will have to run the command with administrator privileges.
On Windows, you need to open a terminal in Administrator Mode.
- Click the Start menu and start typing in "Command Prompt".
- When the "Command Prompt" app appears, right-click and choose "Run as Administrator".
On Mac, you can prepend sudo to the command you originally tried.