Skip to content

Latest commit

 

History

History
208 lines (126 loc) · 5.18 KB

034.Command.line.intro.md

File metadata and controls

208 lines (126 loc) · 5.18 KB

Lesson 034(20 min)

-- Slide --

An introduction to the command line

-- Slide End --

Anna has now managed to connect to her computer in the cloud: but what's this? A text based interface! Anna needs to know how to use this interface if she is to apply the needed security updates!

Files and Directories

When you open your Explorer (Windows) or Finder (OsX) you can see that the contents on your hard drive are organized as files stored inside of folders.

Demonstrate using your Finder

And that the folders can be contained within other folders.

When you open a terminal window you are opening a text based interface into that system.

There is a terminology change though:

Folders are called 'directories'. And files are called, well, 'files'

So how to navigate it?

As the terminal can't give you the same view, it simply has the concept of being positioned in one of those folders. And that directory that it is positioned in is termed the 'working directory'

And you have this concept in your Explorer/Finder as well. Each window you open is positioned on a given directory. And you can move in or out along the directory tree.

You can think of this directory that the Explorer/Finder window is positioned on as being the working directory for that Explorer/Finder window.

Demonstrate using your Finder

Similarly each terminal window you open is positioned on a given directory.

Because the terminal is text based, you need to type in instructions as to what is to happen.

These instructions are called 'commands'.

You type in the command, then when you hit the enter key, the command is executed by the computer.

-- Slide --

In your ssh session

Try the following command:

pwd

pwd is shorthand for print working directory

  • R = Help!
  • G = I'm done

-- Slide End --

When a user logs into a Unix like system they ordinarily start with the working directory positioned in a directory called their home directory:

-- Slide --

The home directory

/home/<<username>>

-- Slide End --

This is the directory where that users personal files, directories and programs are located.

-- Slide --

The home directory

When you typed in pwd is this what you saw?

/home/ubuntu
  • R = No!
  • G = Yes

-- Slide End --

Remember, you ssh'd into the instance as the ubuntu user, and hence this is why your terminal session is positioned here.

-- Slide --

Comments

In the terminal everything after a hash mark is ignored. We can use this to comment our examples:

cmd     # this is a comment that is ignored

-- Slide End --

-- Slide --

Options

Commands often have options

<command> -<option[s]>

-- Slide End --

Demonstrate

eg:

ls -alrt   # list directory contents with options all, long and reverse time

BTW, ls is an abbreviation for "list"

The "man" command provides a description of the meaning and options for a command

Demonstrate

man ls

'q' quits the man command, pages.

Ok: time to put our feet up: we are going take a break and read a very bad story.

-- Slide --

A Story!

-- Slide End --

-- Slide --

Exercise

Agent 00? - we are going to relive your story!

There's a command line cheat sheet at: http://tinyurl.com/command-line-cheat-sheet

Use it to step the through the following tasks: http://tinyurl.com/play-task

  • R = My undercover career needs some help!
  • G = I'm done!

-- Slide End --

But if you have problems remember to ask your neighbours first!

Interesting point about this exercise:

-- Slide --

Why do files have extensions?

  1. To help humans and computers know what's in the file
  2. Because they aren't directories
  3. Files don't have extensions. How dare you!
  4. ANSI standard C12.22 mandates it.
  5. All of the above...

-- Slide End --

Answer A: They are just there to help humans and computers know what's inside the file. Note that these days graphical interfaces hide extensions on certain categories of files.

-- Slide --

What's command are you going to enter to save the world?

  1. CAFEBABE
  2. BADBEAD
  3. DEADCAFE
  4. CAFEBEEF
  5. DEADBEEF

-- Slide End --

Answer E: Any "A's" will be a major worry!

-- Slide --

What's a disadvantage of terminal commands?

  • If you know what you’re doing it’s faster to type than to point with a mouse
  • They keep a history of your commands
  • You can easily replay commands
  • They are simple to automate
  • They are verbose!

-- Slide End --

Answer E: They certainly aren't verbose!