introduction for beginners — no experience needed
$ whoami
Cheatsheet at the end.
A place to type what you want,
instead of
clicking it.
a different way to interact with your computer and/or files
Everything we do in the terminal can be seen in your filesystem.
| macOS | Cmd+Space, type Terminal, Enter |
| Linux | Ctrl+Alt+T, or search Terminal |
| Windows | One extra step — next slide |
Opens a black-ish window with a blinking cursor
Windows ships a different set of commands. Rather than teach two dialects, we install the real ones.
Install Git for
Windows,
then open Git Bash.
It bundles the GNU coreutils — ls,
cp, mv, rm and friends —
so every command we use in this presentation behaves identically to macOS and
Linux.
wsl --install in PowerShell, then reboot. Heavier,
needs admin.Otherwise, come talk to me later and we can discuss other options
anna@laptop:~/Documents$
| | | |
you machine where your turn
The $ means waiting for you.
Yours will look different. That is fine — every prompt is customisable, and it does not change what the commands do.
ls is not
LS(this is also good life advice)
whoami, then datewhoamiiREAD THE ERRORS!
Three commands to answer these questions...
pwd
print working directory.
"Directory" is just the old word for folder. You will see both.
ls # list what's in this folder
ls -l # long: size, date, permissions
ls -a # all: include hidden files
ls -la # both at once
Words starting with - are options. They change
how a command behaves.
cd Documents # go into Documents
cd .. # go up one level
cd ~ # go home
cd - # go back where I just was
cd # also home
change directory.
~ | your home folder |
. | right here |
.. | one level up |
These work almost everywhere a folder name does, not just with
cd.
Look it up 10 times then you will remember it (maybe).
Relative
cd Documents/notes
From wherever I am now. Like "second door on the left".
Absolute
cd /home/anna/Documents
From the very top. Like a full postal address.
Starting with a / means it is an absolute path.
pwd, ls, ls -lacd into a folder, pwd againcd .. back out, then cd ~Try relative and absolute paths
| Tab | finish this word for me |
| Up arrow | the command I just ran |
Tab completes what you are typing (if possible).
It is how you check you typed it right.
cat notes.txt # dump the whole file
less notes.txt # scroll it - press q to quit
head notes.txt # first 10 lines
tail notes.txt # last 10 lines
wc -l notes.txt # how many lines?
q quits less.
cat a short file, then a very long oneless — open it, scroll,
press qhead notes.txt, then tail notes.txtwc -l notes.txtmkdir practice # make a folder
touch notes.txt # make an empty file
cp notes.txt backup.txt # copy
mv notes.txt final.txt # rename
mv final.txt practice/ # ...or move
mv does both jobs. Renaming is moving, as far as
the computer is concerned.
rm notes.txt # delete a file
rm -r oldfolder # delete a folder and everything in it
There is no recycle bin.
rm does not ask, does not warn, and cannot be undone.
Read the line before you press Enter.
(sometimes it does ask but don't rely on it. Use -i when in doubt.)
ls *.txt # every file ending in .txt
cp *.jpg photos/ # copy all the jpegs at once
rm report-* # everything starting with report-
Check before you delete: run it with ls first,
and see exactly what the star matched.
* stands for "anything".
mkdir ~/practice and cd into ittouch a.txt b.txt c.txt — watch them appear in the
file managercp, mv, then rm onels *.txt before rm *.txtPlay around
The output of one command
can become the input of the next.
ls | wc -l # how many things are in here?
ls -l | head # just the top of a long listing
ls > filelist.txt # send the output into a file
| | feed it to the next command |
> | write it into a file (replacing it) |
ls | wc -l — count the lines, of the listing
ls, then ls | wc -lls > filelist.txt, then cat filelist.txtCtrl+C | stop whatever is running |
q | quit a full-screen viewer |
clear | tidy the screen |
ls --help | quick reminder of the options |
man ls | the full manual (q to quit) |
Closing the window always works too.
pwd | where am I |
ls | what is here |
cd | move |
cat | show a file |
less | scroll a file |
head/tail | peek at the top/bottom |
mkdir | new folder |
touch | new file |
cp | copy |
mv | move or rename |
rm | delete, forever |
man | help |
These are some of the most common but there are a lot more.
cd and ls instead of a double-clickKeep practicing
| notes.txt | today's handout — everything we covered, in one file |
| explainshell.com | paste any command, see what every part of it does |
| tldr.sh | manual pages, but only the examples |
| linuxcommand.org | a free book that starts from the very beginning |
| missing.csail.mit.edu | MIT's "Missing Semester" — the natural next step |
| overthewire.org | Bandit: a game to practice your terminal skills |
And the one already on your machine: man.
$ open
presentations.hackenshaw.com/
These slides, with cheatsheet and link to notes.txt.
$ thanks for coming
$ open cmdbox.hackenshaw.com