+ - 0:00:00
Notes for current slide
Notes for next slide

This page intentionally left blank. ⬇️, ➡️, or spacebar 🛰 to start slidedeck.

1 / 27

hacking

Command Line Interface

2 / 27

What is Command Line Interface?

A terminal window is a text-only window in a graphical user interface (GUI) that emulates a console.

A GUI is a type of human-computer interface (i.e., a system for people to interact with a computer) that uses windows, icons, pull-down menus and a pointer and that can be manipulated by a mouse (and usually to some extent by a keyboard as well).

A command is an instruction telling a computer to do something, such as launch a program.

A command line interface (CLI) is an all-text display mode that has a command interpreter running in it and that shows commands, including their arguments, and other data as they are typed in at the keyboard as well as the results of most such commands.

A command interpreter, also referred to as a shell, is a program whose primary function is to read commands that are typed into a console or terminal window and then execute (i.e., run) them.

source

3 / 27

Why learn this?

When working through commands, it may seem strange to learn how to use the command line when you can do everything using the desktop. But here are a few reasons why CLI skills are good to know:

  1. You can use command-line tools that have no GUI equivalent.
  2. You can build automated tools and run them (and you can't do that in a GUI, either) so the computer can do your job for you.
  3. You may have to access computers over a network/internet that either do not have a GUI, or you cannot see them. For example, if you need to talk to a server on your network, you might not be able to get a visual representation of the files on that server and you will have to communicate with this computer "in the dark" using the command line.
4 / 27

Access on macOS: Terminal

For macOS you'll need to do this:

  • Hold down the command key and hit the spacebar.
  • Spotlight Search should appear.
  • Type: terminal
  • Click on the Terminal application. It looks like a black box with >_ inside.

Terminal should now be open.

5 / 27

Access on Windows: Command Prompt or PowerShell

  • Click Start.
  • In "Search programs and files" type: cmd (or powershell)
  • Hit Enter.

Command Prompt
The default command line shell installed in Windows.

PowerShell
PowerShell is a command line shell, scripting language, and task automation program native in Windows.

6 / 27

Access on Linux: Terminal

For Linux you'll need to do this:

  • Hit at the same time the following keys: Control + Alt + t.

Terminal should now be open.

7 / 27

Other options

Running Linux on Windows10

gow
gow is short for Gnu On Windows and installing it will give you access to common UNIX commands, right from the Command Prompt! Recommended.

Cygwin
Cygwin is a "Linux-like environment" for Windows. Here is a cheat sheet for getting started.

Mac: iTerm2
Another option instead of the Terminal with some bonus configuration features.

8 / 27

A note about directories

Directory is another word for what the GUI represents as a "folder." These phrases may be used interchangably.

9 / 27

A note about getting stuck

Command is taking too long? ctrl+c (wrap up and stop doing this) or ctrl+z (stop doing this now)

Stuck in a text file? :q!

Stuck, confused, and panicking? close the window

10 / 27

vi, a text editor that lives inside command line programs, used for quickly editing or reading files. If some documentation is very big, it might overwhelm the screen by opening vi -- the only way out is :q for "quit". Sometimes you need to use an exclamation point to show that you really mean it... :q!.

A note about drag-and-drop

When using the command line on your computer, you can "drag and drop" anything from a folder into the terminal and work with the file there.

11 / 27

Let's practice some commands!

12 / 27

Show current directory

Mac/Linux: pwd

Windows: ch or chdir

13 / 27

Change current directory

Mac/Linux: cd Type/the-path-you-want/here

Windows: cd Type\the-path-you-want\here

It's important to note whether your path starts with a slash or not.

Bonus: .. will take you "up" one level.

14 / 27

Whether the path you are typing in has a slash in front of it or not is significant -- it determines whether or not the computer should look for that path within the context of the folder you are in, or within the context of your entire machine. The slash in front lets the computer know you are setting your path from anywhere, and without the slash, it is within the context of the folder you are in. If you are on the Desktop and want to go to a folder on the desktop, you can just type the name of that folder OR you can drag the folder into the CLI, which will show you the FULL path (and will work no matter what folder you are in).

List this directory's contents

Mac/Linux: ls

Windows: dir

15 / 27

List that directory's contents

Mac/Linux: ls Type/the-path-you-want/here

Windows: dir Type\the-path-you-want\here

Hint: You can drag and drop a folder into the CLI window.

16 / 27

See all files, subfolder and files in subfolders

Windows: tree /f

This is natively only available in Windows, but Mac users can download and install tree. If Mac users have Homebrew installed, they can use brew install tree

17 / 27

Create a directory

Mac/Linux: mkdir name-of-directory

Windows: mkdir name-of-directory

18 / 27

Create a file

Mac/Linux: touch example.txt

Windows: type nul > example.txt

19 / 27

This works well when making things like textfiles, because your operating system is smart enough to know that you want to make a textfile just by adding the .txt extension. Your computer is not smart enough to know that you want a video file if you try to make a video in this way.

Open a file

Mac/Linux: open name-of-file

Windows: name-of-file

20 / 27

Copy a file

Mac/Linux:

cp name-of-file.txt name-of-copy.txt

Windows:

copy name-of-file.txt name-of-copy.txt

21 / 27

Move or rename a file

Mac/Linux:

mv name-of-file.txt new-name.txt

Windows:

move name-of-file.txt new-name.txt

ren name-of-file.txt new-name.txt

22 / 27

A note about deleting

⚠️ ⚠️ ⚠️ It's dangerous! ⚠️ ⚠️ ⚠️

When you delete something on the command line, it deletes it instantly and forever. It does not put it in the Recycle Bin or Trash.

23 / 27

Removing empty directories

Mac/Linux: rmdir name-of-directory

Windows: rmdir name-of-directory

If you try to remove a non-empty directory with rmdir, you will get an error.

24 / 27

Removing files

Mac/Linux: rm -i name-of-file.txt

Windows: del name-of-file.txt

Mac/Linux users: The -i flag is optional but it helps prevent accidental deletion -- it will prompt you to confirm (type y or n). It will read the first letter, so any time of affirmative-sounding word in English will work. Note that typing "yikes" will also work and delete the file. 😅

25 / 27

Learning more

Home

27 / 27

hacking

Command Line Interface

2 / 27
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow