Skip to the content.

Introduction to the Terminal

Aka console, CLI, command line, shell, etc.

-

What we’ll cover

-

Terminal Terminology

-

More Terminal Terminology

*nix - any Unix or Linux operating system. Examples:

-

Getting to Terminal on a Mac

OR

-

Getting Familiar with the Prompt

-

What the prompt looks like

Simple examples: $, >, >>> or ->
Highly customizable.
Default OS X prompt:
Computername:directory username$ eg: Valhalla:HallOfOdin thor$
Idioms: /= root; ~=home

-

Executing commands

Commands are executed when you hit enter
Can chain commands with semicolons
eg: echo "hello"; echo "goodbye"
Obviously incomplete commands will provide intermediate prompt (>)

$ echo "hello
> world"
hello
world

-

Navigating the file system

-

File system structure

*nix file systems are a tree with a root named /
Everything is within / or a descendant directory
directories are delimited with / character
This means we can list the exact position of a dir using its name (called an absolute path)
eg: /usr/bin/, /dev/null, /Users/loki

-

Getting your bearings (basic commands)

-

Moving around

-

Notable directory names and idioms:

-

Class Exercise

-

Class Exercise 2

-

Inspecting files and directories

-

File contents

-

Permissions

ls -l shows file permissions

-rw-r--r--  1 thor  staff  0 Jan 10 16:04 file
-rw-r--r--  1 root  staff  0 Jan 10 16:04 rootFile

-

Running commands as superuser (aka root)

sudo command - Do something as Superuser (requires password)

$ cat file.txt
cat: file.txt: Permission denied
$ sudo cat file.txt
this is a file

-

Creating, copying, moving, renaming, deleting files and directories

-

Three ways to create a file:

-

Create directories with mkdir

-

Editing files

Many terminal-based editors out there. We recommend VIM (explained in console lab 2).
Other options include:

-

The art of Redirection

Every command has access to at least three “file descriptors” (input and output sources). By default these are all routed to the command line

-

Standard file descriptors

-

Redirecting File Descriptors

File descriptors can be rerouted using these commands:

-

Backgrounding

Long running tasks can prevent use of the command prompt.
Run a command in the background with the & character eg: find / -name foo &
Send an already running foreground command to the background with ^z bg (^z suspends the current job, bg resumes it in the background)
It’s often wise to redirect the output when you background something

-

Useful examples