Post on 07-May-2015
Linux beyond Linux beyond lsls and and cdcd
HARVARDHARVARDCOMPUTERCOMPUTERSOCIETYSOCIETY
HARVARDCOMPUTERSOCIETY
What is Linux?What is Linux?
HARVARDCOMPUTERSOCIETY
NO!NO!
Richard StallmanRichard Stallman
HARVARDCOMPUTERSOCIETY
What is GNU/Linux?What is GNU/Linux?
HARVARDCOMPUTERSOCIETY
GNU’s Not UnixGNU’s Not UnixIt’s recursive… get itIt’s recursive… get it
The Free Software The Free Software FoundationFoundation
HARVARDCOMPUTERSOCIETY
Linux is:Linux is:Free SoftwareFree Software
HARVARDCOMPUTERSOCIETY
Linux is: Linux is: $0.00$0.00
HARVARDCOMPUTERSOCIETY
Available in many Available in many distributions on many distributions on many
platformsplatforms
HARVARDCOMPUTERSOCIETY
Ultimate flexibility and Ultimate flexibility and controlcontrol
HARVARDCOMPUTERSOCIETY
Linux is for HAXX0RS!!1Linux is for HAXX0RS!!1
HARVARDCOMPUTERSOCIETY
Movies with bad hackingMovies with bad hacking
HARVARDCOMPUTERSOCIETY
the internets is going downthe internets is going down
HARVARDCOMPUTERSOCIETY
lol hacking??lol hacking??
HARVARDCOMPUTERSOCIETY
Movies with good hackingMovies with good hacking
HARVARDCOMPUTERSOCIETY
Trinity uses Linux.Trinity uses Linux.
HARVARDCOMPUTERSOCIETY
HARVARDCOMPUTERSOCIETY
Linux General PrinciplesLinux General Principles
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
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
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@
HARVARDCOMPUTERSOCIETY
HARVARDCOMPUTERSOCIETY
Your Home DirectoryYour Home Directory~/~/
HARVARDCOMPUTERSOCIETY
The Linux filetree is flexible.The Linux filetree is flexible./ ./ ..// ./ ../symlinkssymlinks
HARVARDCOMPUTERSOCIETY
User configurationsUser configurationsHidden Hidden
files : files : /.hiddenstuff/.hiddenstuff
HARVARDCOMPUTERSOCIETY
Useful programsUseful programs
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
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
HARVARDCOMPUTERSOCIETY
So how do I do anything So how do I do anything useful?useful?
PIPEPIPE> >> |> >> |
HARVARDCOMPUTERSOCIETY
Getting to know your shellGetting to know your shell
tcsh bash zshtcsh bash zsh
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.
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.
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.
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!)
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”););
}}
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 ;
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);
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.
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.
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.