Linux Tutorial
ACM @ UB Dave Fine & Dave Cadigan
Written by Linus Torvalds in 1991 Heavily influenced by Unix and MINIX
◦ MINIX was written from scratch by Torvald's professor, Andrew Tanenbaum, at the University of Helsinki.
Licensed under the GNU General Public License
History
Original source code is available to the public
for use or modification as they see fit Open examples
◦ .ogg ◦ OpenOffice.org ◦ phpBB (forums) ◦ GNU ◦ Mozilla
Closed examples
What is Open Source?
◦ .mp3 ◦ Microsoft Office ◦ Proprietary drivers
Stable
Bleeding Edge Specialized
◦ Slackware ◦ Redhat
◦ Ubuntu ◦ Fedora Core
◦ Damn Small Linux ◦ UBLinux
More at distrowatch.com
Choosing a Distro
Live Disks
◦ Ubuntu, Fedora Core, Knoppix
Hard Drive setup
◦ Many file systems to choose from
‑ ext2/3, ReiserFS
◦ Must allocate swap space (virtual memory)
Dual
Boot
Windows NTFS 70GB Linux ext3 28GB 100 GB Swap 2GB
◦ Install Windows first!!
How to Install
GNOME KDE XFCE many more
Desktop Managers
Shells
bash tcsh
◦ Use text commands to interact with files ◦ Everything is case sensitive ◦ Whitespace sensitive ◦ Most commonly used ◦ used on ubunix
The Command Line
Package managers
Manual installations Build from source
◦ Aptitude ◦ YUM ◦ Automatically resolves dependencies! ◦ .deb ◦ .rpm
◦ $ tar –xvzf ◦ $ ./configure ◦ $ make ◦ $ sudo make install
How to install software
Owner, Groups, Others Read, Write, Execute chmod
◦ 4 2 1
Root user Sudo
◦ chmod 755 filename.txt ◦ chmod u+rwx,ow filename.txt ◦ Similar to Windows Administrator ◦ $ sudo emacs xorg.conf
Permissions
Man pages
◦ man emacs
Strong online community
◦ forums ◦ irc channels ◦ newsgroups
UB
◦ ublinuxsupport@buffalo.edu
More Support
Good for:
◦ System admins ◦ Quick and dirty prototyping for a complex application ◦ Easy way to write custom automated tasks
Bash Scripting
#!/bin/bash #one line comment #make a variable var=“how are you?” echo “hello $USER $var” echo “a”; echo “b”; var=1 #legal, variables are untyped exit 0 #exit code
Basics
X=2 if [ $X eq 1 ] then echo “1” elif [ $X eq 2 ] then echo “2” else echo “none” fi
-eq #equal -ne #not equal -lt #less than -le #less than or equal -gt #greater than -ge #greater than or equal string1 == string2 string1 != string2 string1 > string2 -a file # true if file exists more at LINK
Conditionals
echo "confirm delete all files in directory?" read choice case $choice in "yes") rm * ;; "no") echo "nothing removed" ;; *) echo "Please choose either yes or no" ;; esac
Switch Cases
n=1 while [ $n le 10 ] do echo $n ((n++)) done
for n in `seq 0 10` do echo $n done
for X in red green blue #no C style loops: do for(int i =0;i<10;i++) echo $X done
Loops
array_1[5]=”c” array_2=(1 2 3 4 5) echo ${array_2[2]} # outputs “3” array_3=”abcdefg” #strings are arrays
# note that arrays start counting at 0!
Arrays
function a(){ echo $1 #special variable. first argument return 2; #optional return statement } #last statement in {} needs a semicolon
a hello #outputs “hello” echo $? #outputs 2
Functions
Piping
◦ ps aux | grep firefoxbin #is firefox running?
Redirection
◦ ./script.sh > file.txt #print output from a script to a file ◦ echo “some text >> file.txt #append to a file
History
◦ !em
Math
#execute the latest command that started with “em”
◦ echo $((1+1)) #outputs 2
Other Features
http://www.faqs.org/docs/bashman/bashref_toc.html#
http://www.bittech.net/bits/2007/11/26/bashing_throu http://www.panix.com/~elflord/unix/bashtute.html man bash
citations