📕 workshop-webgl-glsl → Intro to the Command-Line
The Terminal or Command-Line Interface (CLI) is a way of interacting with a computer without a graphical user-interface. Instead, we type commands and use our keyboard to navigate files, execute programs, and fetch data from the web.
- Quick Start
- Opening the Terminal
- Running Commands
- Navigating the File System
- Making Files and Folders
Already a little familiar with the terminal and just want a refresh?
pwd
— print current working directorycd
— change current directoryls
— list files in current directorymkdir
— make a new folder, e.g.mkdir MyFolder/
touch
— create a new empty file, e.g.touch index.js
pbpaste > myfile.txt
— paste clipboard contents into a file (overwriting!)pbpaste >> myfile.txt
— paste clipboard contents into a file (appending)clear
(macOS) orcls
(Windows) — clear the terminalopen .
(macOS Only) — on macOS, open the current working directory in Finder- Ctrl+C — kill current process, e.g. quick a CLI tool
- Tab — auto-complete the current command or path
- Up and Down — navigate previously run commands
- ⌘+T (macOS) or Ctrl+T (Windows) — open a new terminal tab in a different process
If you are on macOS, there's no need to install anything. You just need to open Terminal.app
which comes with your system.
Choose one of the following to open the app:
-
Pushing ⌘ + Space to open Spotlight, and then searching for Terminal.app and hitting Enter to open.
-
Open Finder, go to your Applications folder, then open the Utilities folder and look for Terminal.app. Double-click it to open.
If you are on Windows, we have to install an emulator so that we can enter macOS-style commands. I recommend installing cmder. Download the ZIP and extract the contents to your Program Files or some other location on your computer.
Once installed, double-click the cmder.exe file to open the terminal.
To run a command, you can type it into the terminal window and hit Enter. You can use the Up and Down arrow keys to navigate previously run commands.
Try typing in the pwd
command and then hitting Enter:
The pwd
command will print the current path of the terminal process, which might be different depending on your system.
- On macOS it may appear as
/Users/YOUR_USER_NAME
- On Windows it may apper as
C:\Users\YOUR_USER_NAME
The first thing you should learn to do is navigate around different folders on your system.
We will use the cd
command (change directory).
You can navigate to a new folder by specifying an absolute file path:
# On macOS
cd /Users/YOUR_USER_NAME/Desktop
# On windows
cd C:\Users\YOUR_USER_NAME\Desktop
💡 Lines beginning with
#
are treated as comments and will do nothing.
Now, all future commands will be executed from within this new folder.
You can again test to see if the command worked by using pwd
to get the current file path.
Once you navigate to a folder like your Desktop, you can use relative paths to go in and out of folders. Imagine you have a folder on your desktop like so:
You can do the following to move into that folder:
# Move into the folder
cd DFPI-Project/
Or, once you've moved into the folder, you can move back out of it, by going up one directory:
# Move up one directory
cd ../
The final /
slash is optional. Here are some other examples:
# Going deep into folders
cd SomeFolder/NestedFolder/OneMore
# Going up multiple times and then into another folder
cd ../../SomeFolder
If you file path has spaces in it, you should encapsulate the entire path with double quotes like so:
cd "My Folder/src/foo"
To list files in the current directory, use ls
.
ls
You can use the mkdir
command to create a new folder in the working directory.
mkdir MyFolder/
You can use the touch
command to create a new empty file in your working directory:
# this creates an empty JavaScript file called 'index.js'
touch index.js
If the file already exists, this will do nothing.
You can use pbpaste
like so to paste the clipboard contents into a file (overwriting the file!).
# overwrite index.js with clipboard contents
pbpaste > index.js
If you'd rather paste the contents to the end of the file without overwriting the entire thing, you can use >>
which is for appending:
# append index.js with clipboard contents
pbpaste >> index.js