Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to...

91
Introduction to Linux Workshop September 30 2014

Transcript of Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to...

Page 1: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Introduction to Linux Workshop September 30 2014

Page 2: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Introduction

Rob Lane

HPC Support Research Computing Services

CUIT

Page 3: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Introduction

Linux Basics for Beginners

Page 4: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Introduction

Linux Basics for Beginners

(No HPC Yet)

Page 5: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Introduction

1st Hour: Slides + Hands-on 2nd Hour: Hands-on

Page 6: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Introduction

First Workshop

Page 7: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

History

This will be quick

Page 8: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

History

Linux is old

1991

Page 9: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

History

For our purposes

Linux = Unix

Page 10: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

History

Unix is very old

1969

Page 11: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

History

Unix created by engineers for engineers

Page 12: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

History

Unix was designed to be simple and powerful

Page 13: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Access

Did everyone get a user ID?

Page 14: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Access

Windows Instructions 1.  Search for putty on Columbia home page 2.  Select first result 3.  Follow link to Putty download page 4.  Download putty.exe 5.  Run putty.exe

Page 15: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Access

Mac Instructions 1.  Run terminal

Page 16: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Access

Mac (Terminal) $ ssh [email protected]

Windows (Putty)

Host Name: didius.cc.columbia.edu

Page 17: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Access

Aside System: cunix.columbia.edu User: Your UNI

Page 18: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Prompt

[user1@didius ~]$

•  User name •  System name •  Name of current directory

~ is special

Page 19: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

pwd

$ pwd

“Print working directory”

Page 20: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Directory Path

$ pwd /workshop/home/user1

Page 21: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

ls

$ ls

“List directory” Not very interesting.

Page 22: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

cd

$ cd /

“Change directory” $ pwd

Page 23: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

ls

$ ls

$ ls –l

Long listing.

Page 24: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

cd

$ cd $ pwd

cd with no arguments takes you back home

Page 25: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

..

$ pwd $ cd ..

$ pwd

“..” means “the directory above this one”

Page 26: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

.

$ pwd $ cd .

$ pwd

“.” means “this directory”

Page 27: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

ls -a

$ cd $ ls -a

Can combine options

$ ls –la

Page 28: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

~

$ pwd $ cd ~

$ pwd

“~” means “home directory”

Page 29: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Paths

$ cd tmp $ cd /tmp

Absolute: starts with “/” Relative: doesn’t

Page 30: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

cp

$ cd $ cp /tmp/keets .

$ ls

Page 31: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

rm

$ cp keets junk $ ls

$ rm junk

$ ls

Page 32: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

cat

$ cat keets

Page 33: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

mv

$ mv keets keats $ ls

Page 34: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

mkdir

$ mkdir tmp $ mv keats tmp

$ cd tmp

$ ls

Page 35: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

rmdir

$ pwd $ mv keats ..

$ cd ..

$ rmdir tmp

$ ls

Page 36: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

who am i

$ whoami $ who am i

$ id

$ groups

Page 37: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

id, groups

$ id rl2226 $ groups rl2226

Page 38: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

who

$ who

Page 39: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

w

$ w

Page 40: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

bash

•  bash is a “shell”

•  It prints the prompt and interprets what you enter

•  It has many keyboard shortcuts that can really speed up your work

Page 41: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

bash

$ ls jeats ls: jeats: No such file or directory

•  Up arrow to retrieve the command •  Left and right arrows to navigate on line •  Change the “j” to a “k” and rerun

Page 42: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

bash

“^” means “hold down control” ^a : go to beginning of line ^e : go to end of line ^k: delete to end of line Many more useful bash commands

Page 43: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

bash

$ ls k[tab] $ ls keats

•  Tab completion •  Works for commands as well

Page 44: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

man

$ man ls

Display manual for “ls” command

Page 45: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

ls -l

$ ls –l

total 4 -rw------- 1 user1 workshop 573 Sep 29 22:00 keats

•  File type and permissions •  Link count •  User •  Group •  Date last changed •  File name

Page 46: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

File Type

$ ls –l

total 4 -rw------- 1 user1 workshop 573 Sep 29 22:00 keats

- Normal File d Directory l Link

Others Various Special Files

Page 47: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Permissions

$ ls –l

total 4 -rw------- 1 user1 workshop 573 Sep 29 22:00 keats

r read w write x execute

others various special settings

Page 48: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Links

$ ls –l

total 4 -rw------- 1 user1 workshop 573 Sep 29 22:00 keats

We’ll ignore links for now.

Page 49: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

User

$ ls –l

total 4 -rw------- 1 user1 workshop 573 Sep 29 22:00 keats

The user that owns this file.

Page 50: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Group

$ ls –l

total 4 -rw------- 1 user1 workshop 573 Sep 29 22:00 keats

The group that owns this file.

Page 51: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Size

$ ls –l

total 4 -rw------- 1 user1 workshop 573 Sep 29 22:00 keats

The size of this file. Here listed in bytes.

Page 52: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Last Change Date

$ ls –l

total 4 -rw------- 1 user1 workshop 573 Sep 29 22:00 keats

The last time the file was changed.

Page 53: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Name

$ ls –l

total 4 -rw------- 1 user1 workshop 573 Sep 29 22:00 keats

The file name.

Page 54: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Permissions

$ ls -l /bin/bash

-rwxr-xr-x 1 root wheel 768952 Sep 25 15:31 /bin/bash

Page 55: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Permissions

$ ls -l /bin/bash

-rwxr-xr-x 1 root wheel 768952 Sep 25 15:31 /bin/bash

r read w write x execute

others various special settings

Page 56: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Permissions

$ ls -l /bin/bash

-rwxr-xr-x 1 root wheel 768952 Sep 25 15:31 /bin/bash

Nine permission settings

Page 57: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Permissions

$ ls -l /bin/bash

-rwxr-xr-x 1 root wheel 768952 Sep 25 15:31 /bin/bash

Three groups of three

Page 58: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Permissions

$ ls -l /bin/bash

-rwxr-xr-x 1 root wheel 768952 Sep 25 15:31 /bin/bash

First group: owner

read yes write yes execute yes

Page 59: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Permissions

$ ls -l /bin/bash

-rwxr-xr-x 1 root wheel 768952 Sep 25 15:31 /bin/bash

Second group: group

read yes write no execute yes

Page 60: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Permissions

$ ls -l /bin/bash

-rwxr-xr-x 1 root wheel 768952 Sep 25 15:31 /bin/bash

Third group: everyone else

read yes write no execute yes

Page 61: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

date

$ date Tue Sep 30 13:27:29 EDT 2014

Page 62: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Output Redirection

$ cd $ date > thedate

$ cat thedate

Page 63: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Output Redirection

$ cd $ ls –l > myhome

$ cat myhome

Page 64: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

sort

$ sort keats

Page 65: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Input Redirection

$ sort < keats

Page 66: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Input/Output Redirection

$ sort < keats > sorted $ cat sorted

Page 67: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Appending

$ date >> thedate $ cat thedate

Useful for log files

Page 68: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

grep

$ grep planet keats When a new planet swims into his ken;

Find all lines containing “planet” in “keats”

Page 69: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Pipes

$ cat keats $ cat keats | grep planet

When a new planet swims into his ken;

Pipes connect output from one command to the input of another command

Page 70: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Editing

No single obvious choice for editor •  vi – simple but difficult at first •  emacs – powerful but complex •  nano – simple but not really standard

Page 71: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

nano

$ nano keats

“^” means “hold down control” ^a : go to beginning of line ^e : go to end of line ^k: delete line ^o: save file ^x: exit

Page 72: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

less

$ less /var/log/messages

•  Used to read (not edit) files •  Very useful command

Page 73: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

less

[space] : next page b : previous page g : go to end of file ^g : display location in file / : search n: repeat search

Page 74: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

sleep

$ sleep 5

•  More useful than it seems

Page 75: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

echo

$ echo hi hi

•  More useful than it seems

Page 76: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Multiple Commands

$ sleep 5; echo hi hi

•  Use ; to separate commands

Page 77: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Job Control

$ sleep 60 ^c

$

•  Use control-c to stop a running command

Page 78: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Job Control

$ sleep 60; echo hi ^c

What happened? Why?

Page 79: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

exit

$ exit

•  Logs out •  There are other ways of logging out

$ logout

$ ^d

Page 80: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

ps

$ ps

•  Lists the processes you have running in this session

Page 81: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

ps

$ ps -e

•  List every process

Page 82: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

ps

$ ps -aux

•  List every process with a lot more information

•  Flags for ps are numerous and inconsistent

Page 83: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

top

$ top

•  Lists running processes •  Updates every 3 seconds •  Many options to change display •  Many other top-like commands exist.

Page 84: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Questions?

Any questions?

Page 85: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Other Topics

•  This is the end of the slides proper

•  Many other commands and concepts that could be covered

•  Following slides just list possibilities

Page 86: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Other Topics

•  Environment variables •  $PATH •  which •  type

Page 87: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Other Topics

•  More process control •  ^z •  bg, fg •  jobs (command)

Page 88: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Other Topics

•  Standard directories •  bin •  dev •  etc •  tmp •  usr •  var

Page 89: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Other Topics

•  File systems •  df •  Space usage •  du

Page 90: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Other Topics

•  Processes •  fork() •  exec() •  kill

Page 91: Intro to Linux - Columbia University Libraries · • Updates every 3 seconds • Many options to change display • Many other top-like commands exist. Questions? Any questions?

Other Topics

•  Shell scripts

•  Programming