linux beyond ls and cd harvard computer society. harvard computer society what is linux?

39
Linux beyond Linux beyond ls ls and and cd cd HARVARD HARVARD COMPUTER COMPUTER SOCIETY SOCIETY

Post on 18-Dec-2015

222 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

Linux beyond Linux beyond lsls and and cdcd

HARVARDHARVARDCOMPUTERCOMPUTERSOCIETYSOCIETY

Page 2: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

What is Linux?What is Linux?

Page 3: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

NO!NO!

Richard StallmanRichard Stallman

Page 4: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

What is GNU/Linux?What is GNU/Linux?

Page 5: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

GNU’s Not UnixGNU’s Not UnixIt’s recursive… get itIt’s recursive… get it

The Free Software The Free Software FoundationFoundation

Page 6: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Linux is:Linux is:Free SoftwareFree Software

Page 7: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Linux is: Linux is: $0.00$0.00

Page 8: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Available in many Available in many distributions on many distributions on many

platformsplatforms

Page 9: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Ultimate flexibility and Ultimate flexibility and controlcontrol

Page 10: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Linux is for HAXX0RS!!1Linux is for HAXX0RS!!1

Page 11: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Movies with bad hackingMovies with bad hacking

Page 12: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

the internets is going downthe internets is going down

Page 13: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

lol hacking??lol hacking??

Page 14: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Movies with good hackingMovies with good hacking

Page 15: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Trinity uses Linux.Trinity uses Linux.

Page 16: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Page 17: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Linux General PrinciplesLinux General Principles

Page 18: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

General PrinciplesGeneral Principles

Less is more (no news is good news)Less is more (no news is good news) Small programs that do one thing Small programs that do one thing

really wellreally well (Almost) everything is open-source(Almost) everything is open-source Input and output to programs is Input and output to programs is

plain-text: easy to see what plain-text: easy to see what programs doprograms do

Page 19: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Principles cont.Principles cont.

Multi-user computing Multi-user computing environment with permissionsenvironment with permissions

Everything is a file. Everything is a file. Everything.Everything.

Ctrl-Z, Ctrl-D, Ctrl-C – typical Ctrl-Z, Ctrl-D, Ctrl-C – typical ways to get out of somethingways to get out of something

If you don’t know, RTFM: If you don’t know, RTFM: manman

Page 20: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Where is everything?Where is everything?

bin/ etc/ lib/ misc/ oracle@ scratch@ tmp/bin/ etc/ lib/ misc/ oracle@ scratch@ tmp/boot/ home@ local/ mnt/ proc/ shells/ usr/boot/ home@ local/ mnt/ proc/ shells/ usr/cdrom@ initrd/ lost+found/ nfs/ root/ srv/ var/cdrom@ initrd/ lost+found/ nfs/ root/ srv/ var/

dev/ initrd.img@ media/ opt/ sbin/ sys/ vmlinuz@ dev/ initrd.img@ media/ opt/ sbin/ sys/ vmlinuz@

Page 21: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Page 22: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Your Home DirectoryYour Home Directory~/~/

Page 23: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

The Linux filetree is flexible.The Linux filetree is flexible./ ./ ..// ./ ../symlinkssymlinks

Page 24: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

User configurationsUser configurationsHidden Hidden

files : files : /.hiddenstuff/.hiddenstuff

Page 25: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Useful programsUseful programs

Page 26: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Useful Linux ProgramsUseful Linux Programs

finger, writefinger, write find, which, find, which, whereiswhereis

grepgrep ps, kill, ps, kill, killall, topkillall, top

jobs, fg, screenjobs, fg, screen quota, du, dfquota, du, df

lnln dig –tracedig –trace ping, wget, curlping, wget, curl emacs, viemacs, vi echo, catecho, cat head, tail, head, tail, less, moreless, more

chown, chmodchown, chmod

Page 27: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

DaemonsDaemons

Programs that serve stuff all the time.Programs that serve stuff all the time. Common services:Common services:

– Apache (Apache (httpdhttpd))– OpenSSH (OpenSSH (sshdsshd))– LDAP (LDAP (flapdflapd))– SAMBA-Windows Networking (SAMBA-Windows Networking (smbdsmbd))– Cron-Scheduled Tasks (Cron-Scheduled Tasks (croncron))– Others: Others: inetdinetd, , xinetdxinetd, , xvncxvnc

Page 28: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

So how do I do anything So how do I do anything useful?useful?

PIPEPIPE> >> |> >> |

Page 29: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Getting to know your shellGetting to know your shell

tcsh bash zshtcsh bash zsh

Page 30: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Environment variablesEnvironment variables

Control the characteristics of the shellControl the characteristics of the shell– View them withView them with [set]env [set]env, or , or $VARIABLE$VARIABLE– Set them with Set them with exportexport– Change up your prompt! Change up your prompt! export export PS1=“myCOOLprompt: ”PS1=“myCOOLprompt: ”

But these have to be declared every But these have to be declared every time you use your shell.time you use your shell.– Solution: Solution: ~/.profile, ~/.bash_profile~/.profile, ~/.bash_profile, etc., etc.

Page 31: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

But if we have variables…But if we have variables…

And we have all these nifty little And we have all these nifty little programs that can be strung programs that can be strung together…together…

Can we make our own programs??Can we make our own programs??

YES.YES. Linux is beautiful.Linux is beautiful.

Page 32: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Shell ScriptsShell Scripts

Shell scripts are “programs” that are Shell scripts are “programs” that are completely uncompiled, but read and completely uncompiled, but read and executed by the shell line by line.executed by the shell line by line.

Typically end in .shTypically end in .sh Must be chmod’ed executable.Must be chmod’ed executable. Start with a “shabang” – tells the Start with a “shabang” – tells the

shell what to use to interpret it. e.g.,shell what to use to interpret it. e.g.,– #! /bin/bash#! /bin/bash for a bash script. for a bash script.

Page 33: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Quick overview of BASH Quick overview of BASH scriptingscripting

We can solve most of the problems We can solve most of the problems presented in PS#1 with BASH scripts.presented in PS#1 with BASH scripts.

For instance, here’s a demo that For instance, here’s a demo that relates to the hacker edition:relates to the hacker edition:– Interlocked diamonds (sorry, don’t want Interlocked diamonds (sorry, don’t want

to give it totally away!)to give it totally away!)

Page 34: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

BASH vs. CBASH vs. C#! /bin/bash#! /bin/bash

number=3number=3name=name=“bob”“bob”echo echo “$name is your “$name is your

chosen name, $number chosen name, $number your chosen number.”your chosen number.”

let let “inc=number+1”“inc=number+1”ifif [[ “$inc”“$inc” –eq –eq “4”“4” ]]

then echo then echo “Addition “Addition works like a charm.”works like a charm.”

fifi

#include <stdio.h>#include <stdio.h>#include <cs50.h> #include <cs50.h>

int number = 3;int number = 3;string name = string name = “bob”“bob”;;printf(printf(“%s is your chosen “%s is your chosen

name, %d your chosen name, %d your chosen number.\n”number.\n”, number, , number, name);name);

int inc = number++;int inc = number++;if (if ( inc == 4 inc == 4 ) {) {

printf(printf(“Addition works “Addition works like a charm.\n”like a charm.\n”););

}}

Page 35: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

BASH vs. CBASH vs. C

All variables are All variables are stringsstrings

Variables are Variables are accessed with accessed with $VAR$VAR

Runs other Linux Runs other Linux programs to do its programs to do its workwork

Spacing usually Spacing usually matters.matters.

No line endingsNo line endings

Multiple types, Multiple types, must be declaredmust be declared

Variables do not Variables do not have prefixeshave prefixes

Runs subroutines Runs subroutines or functions from or functions from libraries to do worklibraries to do work

Spacing matters a Spacing matters a lot less.lot less.

Lines end in ;Lines end in ;

Page 36: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

BASH vs. CBASH vs. C#! /bin/bash#! /bin/bash

number=0number=0whilewhile [[ “$number”“$number” –lt –lt “5”“5” ]]dodo

echo echo “You want something “You want something greater than 5.”greater than 5.”echo –n echo –n “Enter a number: ”“Enter a number: ”read numberread number

donedoneecho echo “$number is greater “$number is greater

than 5!”than 5!”

#include <stdio.h>#include <stdio.h>

int number = 0;int number = 0;

while (while (number < 5number < 5) {) {

printf(printf(“You want “You want something greater than something greater than 5.\nEnter a number: ”5.\nEnter a number: ”););

number = GetInt();number = GetInt();

}}

printf(printf(“%d is greater “%d is greater than 5!”than 5!”, number);, number);

Page 37: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

As you can see there are many As you can see there are many similarities…similarities…

BASH is a programming BASH is a programming language in and of itself.language in and of itself.

You put all the little pieces of Linux together in the You put all the little pieces of Linux together in the ways that suit ways that suit you you best. It’s your computer to best. It’s your computer to

control.control.

Page 38: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

got graphix?got graphix?

So far we’ve been staring a lot at So far we’ve been staring a lot at text consoles.text consoles.

Linux does allow for the display of Linux does allow for the display of graphics:graphics:– X11 on nice – demo it!X11 on nice – demo it!– Window managers: Gnome, KDEWindow managers: Gnome, KDE– You can see these on the SC Lab You can see these on the SC Lab

computers, or in most desktop Linux computers, or in most desktop Linux distros, e.g., Ubuntu, Suse, Red Hat, etc.distros, e.g., Ubuntu, Suse, Red Hat, etc.

Page 39: Linux beyond ls and cd HARVARD COMPUTER SOCIETY. HARVARD COMPUTER SOCIETY What is Linux?

HARVARDCOMPUTERSOCIETY

Till next time...Till next time...http://http://hcshcs.harvard.edu/~.harvard.edu/~

powerpakpowerpakfor a copy of this presentationfor a copy of this presentation

Come to HCS weekly meetingsCome to HCS weekly meetings

Wednesdays at 8pm, SOCH Wednesdays at 8pm, SOCH 307307

Free Pizza courtesy of Google.Free Pizza courtesy of Google.