Professional Documents
Culture Documents
Electronic Presentation
Copyright 2011, Oracle and/or its affiliates. All rights reserved. Disclaimer This document contains proprietary information and is protected by copyright and other intellectual property laws. You may copy and print this document solely for your own use in an Oracle training course. The document may not be modified or altered in any way. Except where your use constitutes "f i use" under copyright l i "fair " d i h law, you may not use, share, d h download, upload, copy, print, di l l d l d i display, perform, reproduce, f d publish, license, post, transmit, or distribute this document in whole or in part without the express authorization of Oracle. The information contained in this document is subject to change without notice. If you find any problems in the document, please report them in writing to: Oracle University, 500 Oracle Parkway, Redwood Shores, California 94065 USA. This document is not warranted to be errorfree. Restricted Rights Notice If this documentation is delivered to the United States Government or anyone using the documentation on behalf of the United States Government, the following notice is applicable: U.S. GOVERNMENT RIGHTS The U.S. Governments rights to use, modify, reproduce, release, perform, display, or disclose these training materials are restricted by the terms of the applicable Oracle license agreement and/or the applicable U S Government contract. U.S. contract Trademark Notice Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. Guru Labs L.C. The contents of this course and all its modules and related materials, including handouts to audience members, are copyright 2011 Guru Labs L.C. No part of this publication maybe stored in a retrieval system, transmitted or reproduced in anyway, including, but not limited to, photocopy, photograph, magnetic, electronic or other record, with out the prior written permission of Guru Labs. This curriculum contains proprietary information which is for the exclusive use of customers of Guru Labs L C and is not to be shared with L.C., personnel other than those in attendance at this course. This instructional program, including all material provided herein, is supplied without any guarantees from Guru Labs L.C. Guru Labs L.C. assumes no liability for damages or legal action arising from the use or misuse of contents or details contained herein. Photocopying any part of this manual without prior written consent of Guru Labs L.C. is a violation of federal law. This manual should not appear to be a photocopy. If you believe that Guru Labs training materials are being photocopied without permission, please email Alert@gurulabs.com or call 1-801-298-5227. Guru Labs L.C. accepts no liability for any claims, demands, losses, damages, costs or expenses suffered or incurred howsoever arising from or in connection with the use of this courseware. All trademarks are the property of their respective owners. Version: OEL120S-O54-A00
Version: OEL120-O54-A00
1 2 3 4 5 6 7 8 9 10 11
What is Linux? Multi-user Concepts The X Window System The Linux Filesystem Manipulating Files Archiving and Compression Shell Basics Command Shells Shell Scripting for DBAs Process Management and Job Control Regular Expressions
12 13 14 15 16 17
Text Processing Text Editing The Secure Shell (SSH) Intro to Software Management Messaging Printing
Schedule:
y Restrooms y Telephone and network access y Break rooms and other resources y Emergency procedures
Participant Introductions:
y Name and employer y Background and relevant experience y Objectives and topics of interest
Typographic Conventions:
Line Wrapping:
password required /lib/security/pam_cracklib.so retry=3a type= minlen=12 dcredit=2 ucredit=2 lcredit=0 ocredit=2 password required /lib/security/pam_unix.so use_authtok
File: /e + +
#L #P Pe Al #S
description of each action and its effect is shown to the right or under the action. Alternating actions are shaded to aid readability. For example, the following action list describes one possible way to launch and use xkill to kill a graphical application:
Action Lists:
Open the "run" dialog.
xkill
ution string
Launch xkill. The cursor should change, usually to a skull and crossbones. Click on a window of the application to kill. Indicate which process to kill by clicking on it. All of the applications windows should disappear.
Callouts Occasionally lab steps will feature a shaded line that extends to a note in the right margin. This note, referred to as a "callout", is used to provide additional commentary. This commentary is never necessary to complete the lab succesfully, and could in theory be ignored. However, callouts do provide valuable information such as: insight into why a particular
orted
$ cat # whoami Open the "run" dialog. . . . root Launch xkill. The cursor should change, usually to a skull xkill prompt will contain additional information. For example, In general, at Occasionally the
crossbones. when portions of a lab task should be performed on two different stations, When examp Click will a window on be expanded to: Command Prompts: of the application to kill. the following the prompt Indicate which process to kill by clicking on it. All of $ cat stationX$ whoami applications windows should disappear.
to complete the lab succesfully, and could in theory be ignored. However, callouts information such as: insight into why a particular command or option is being use Callouts: obvious command output, and tips or tricks such as alternate ways of accomplish
root:x . . . clints root@stationY's password: password Occasionally lab whoamiwill feature a shaded line that extends to a note in the right . . . stationY# steps referred to as a "callout", is used to provide additional commentary. This comment root guru stationX$ ssh root@stationY Callouts
100% 2874
2.8KB/s
00:00
What is Linux?
Unix Timeline
1965 GE, MIT, and AT&T begin work on MULTICS 1969 MULTICS dropped by AT&T, and replace it with UNICS 1973 Unix rewritten in C, making it portable 1975 Sixth Edition released; source licensed at low cost 1979 Seventh Edition released, foundation of future Unix systems 1985 Eighth Edition, based on 4.1BSD 1988 4.3BSD Net/1: rst free software release 1989 Tenth Edition, never released publicly; Plan9 First Edition replaces it in 1992 (open sourced in 2002) 1990 AT&T Unix System V Release 4. 1991 Minix 1.5 released. 1992 Linus Torvalds releases 0.12 Linux under the GPL.
Linux Features
x86, Alpha, MIPS, PowerPC, Arm, SPARC, ... 64bit on AMD64, Alpha, UltraSPARC, Itanium, ... Preemptive multitasking, memory protection USB, FireWire, SCSI, FibreChannel Ethernet, Token Ring, FDDI, ATM, WAN cards IPv4, IPv6, IPsec, IPX, AppleTalk Bridging, Firewalling, VPN, QoS Bandwidth Mgt. Much, much more...
What is a Distribution?
One-stop-shopping for Linux Typical Linux distributions provide the following: collection of applications along with the Linux kernel installation program way to selectively install applications documentation support There are over 100 different, actively developed distributions some very specialized (ex. Linux Router Project)
Components of a Distribution
Most Linux distributions provide the same basic software: GNU software BSD and Linux utilities X.Org GNOME, KDE, and other GUI components Differences between distributions are primarily a matter of: packaging and support Added features
Standardization
POSIX -- IEEE 1003 Single UNIX Specication, v3 (SUSv3) Filesystem Hierarchy Standard (FHS) Linux Standards Base (LSB)
http://public-yum.oracle.com
Publicly available YUM repository of OEL packages from install media Does not include errata Free Validated Congurations http://linux.oracle.com/validated-configurations
Multi-user Concepts
Multi-user Concepts
Traditional Unix operation mainframe host <> dumb terminal Linux has been multi-user from the beginning Multi-user vs. multiple users Multi-user vs. multitasking Importance of the system knowing who you are security enforcing limits on system resources
got root?
Many operating systems have the concept of a super user This super, or privileged, user has special access rights and privileges on the system The root user is the privileged user on most Unix systems Has the user ID (UID) of zero (0)
Logging In
Serial terminals getty login Virtual terminals mingetty login Graphical logins xdm, gdm, kdm, etc. Network logins telnet, rlogin, ssh, etc.
Character Encodings
Encodings Examples: ASCII, ISO-8859-X, UTF-8, UTF-16, UCS-4, UTF-32 ASCII most widely used only 128 characters basis of other encodings such as ISO-8859-X Unicode standard for which multiple encodings exist legacy support for ASCII still growing Tools iconv, convmv
Locales
Locales are collections of settings for a region Examples of settings include language, text formatting, and sorting Locale Environment Variables Viewing/Modifying locale settings with locale & setlocale() Scripting using LANG=C
Lab 2
Estimated Time: 30 minutes
Starting X
X already running with a graphical login On Oracle Enterprise Linux, runlevel 5 by default From a text virtual terminal login, use startx startx is a shell script that eventually runs xinit can run xinit manually, but by default only starts the X server
Customizing X Sessions
X resources database of customized settings for X applications manipulating using xrdb /.Xresources text le of X resource settings merged using xrdb at X startup Modify Keyboard Mappings: xmodmap Per Window Information: xwininfo, xprop Run from within X; without options, will prompt to click on window to display information
Desktop Environments
Complete interface Consistent look and feel Window manager plus "stuff" File manager Applications Utilities Application Launcher Standardized working environment
KDE
KDE consistent desktop environment all KDE applications have a common look Built on the Qt library Primarily built in C++, though bindings also exist for many other languages Themeable Uses its own window manager, kwin seamlessly integrated
KDE Panel
Menus Application launchers Embedded applications Virtual desktop manager
KDE Applications
Wide variety of applications Many utilities, much like GNOME kwrite (KDE text editor), kcalc (calculator) Many applications Konqueror (web browser/le manager extraordinaire), KMail (email client), Kontact (extensive PIM suite), Kopete (instant messaging client) Ofce Suite KOfce KDE apps run on GNOME, and vice-versa
GNOME
GNOME consistent desktop environment all GNOME applications have a common look Uses the GTK library programmable in many different programming languages Theme-able Currently uses Metacity as the default window manager Originally used Enlightenment, then Sawsh window managers were used
GNOME Preferences
The GNOME desktop is highly congurable fonts le types and programs wallpaper screensavers keyboard setup multimedia setup
GNOME Panel
Launcher Menu Application Launcher Applets applications running within the Panel Virtual Desktop control
GNOME Applications
Wide variety of applications Utilities gedit (notepad like text editor), gcalctool (calculator) Applications Evolution (email/PIM suite), Gnumeric, Abiword, OpenOfce.org, Balsa, GnuCash (personal nancial management) GNOME apps run on KDE, and vice-versa
Lab 3
Estimated Time: 15 minutes
Filesystem Support
Support for dozens of lesystem types including: Minix, ext2, MS-DOS, UMSDOS, VFAT, NTFS, NFS, ISO9660, HPFS, SYSV, SMB, AFFS, BeFS, BFS, EFS, NWFS, QNX, RFS, UDF, UFS Support for advanced logging / journaling lesystems: ReiserFS, ext3, JFS, XFS, Reiser4 Current default standard for Linux: ext3
OFA Characteristics
Optimal Flexible Architecture was introduced to optimize the relationship between database les and the host operating system. You can use OFA to: Distribute les across multiple mount points to: balance I/O for performance, and increase reliability Handle large and growing directories Administer multiple releases
File Ownership
Each le is owned by a specic UID and GID chown Change the user (UID) ownership Only root can change ownership to another user Can also be used to change group at the same time chgrp Modify just the group (GID) ownership
Lab 4
Estimated Time: 25 minutes
Manipulating Files
Directory Manipulation
Standard manipulation commands mkdir creates directories -m: set permissions on new directory -p: Create parent directories if they don't exist rmdir deletes empty directories -p: Remove empty parent directories
File Manipulation
Standard manipulation commands cp copies les and directories -a: Archive recursively, preserving permissions, ownership, links and not following symbolic links, etc. -r: copy directories recursively mv moves or renames les and directories -u: Overwrite only if destination is older than source Shared options -f: replace le without prompting (see -i) -i: prompt before replacing a le
Filesystem Links
Created with ln Hard links directory entry that references the same inode as another directory entry can't span lesystems can't create hard links to non-existent le can't create hard links to directories do not require additional storage space (i.e. blocks) Symbolic links le that references another le via path and name can reference directories can span lesystems can reference non-existent les occupy space
Displaying Files
cat displays entire le(s) more displays le(s) one screen at a time less more sophisticated and congurable pager
Previewing Files
head displays rst 10 (by default) lines of le tail displays last 10 (by default) lines of le tail -f to watch a le be appended to Use the -n option to congure how many lines to view
Lab 5
Estimated Time: 35 minutes
compress
default action deletes original after creating new compressed le standard le extension: .gz much higher compression ratio than compress gunzip or zcat decompresses les compressed with gzip gunzip decompresses the le on disk (removing the original, compressed le); zcat does not zcat outputs uncompressed data to STDOUT
Lab 6
Estimated Time: 15 minutes
Shell Basics
Communication Channels
All running programs in Unix have at least three communication channels STDIN (standard in): where the program gets input. This is usually the keyboard. STDOUT (standard out): where the program sends output. This is usually the terminal. STDERR (standard error): where the program sends error messages. This is usually the terminal.
File Redirection
File or I/O redirection allows you to redirect STDIN, STDOUT, and STDERR to les Requires special notation on the command line redirect standard input with <
$ ls -al | less
more complex example:
Filename Matching
Many commands take a list of lenames as arguments tedious to manually type many lenames Wildcard patterns provide an easy way to supply many lenames as arguments Historically called "le globbing" Wildcard patterns are specied with special characters
Brace Expansion
Allows generation of arbitrary strings Similar to wildcards, but target les or directories don't need to exist Can have optional preamble and/or postamble {m,n,o,on} expands to: m, n, o and on d{m,n,o,on}t expands to: dmt, dnt, dot & dont, where d is the preamble and t is the postamble Can be combined with wildcards; brace expansion occurs before globbing
Nesting Commands
Command Substitution Substitutes output of command in place of "embedded" command Nesting Commands command $(command) Evaluating Command Output eval command
Lab 7
Estimated Time: 45 minutes
Command Shells
Shells
Bourne Shell (sh) C Shell (csh) Korn Shell (ksh) Bourne Again Shell (bash) Enhanced C Shell (tcsh) Public Domain Korn Shell (pdksh) Z Shell (zsh)
$ echo $SHELL
Identifying the current shell:
$ ps -f
sh: Prompts
Simple. No bells or whistles like tcsh or bash Prompt is set using the PS1 variable
$ history
Execute previous command
$ !!
Last command starting with xy
$ !xy
Run command found on specied history line number:
$ !42
Special Control sequences can search history r see man bash for details Fix Command may be used for advanced searching and editing:
$ fc -1 -5
$ set -o vi
to set emacs editing mode (default)
$ set -o emacs
bash: "shortcuts"
Directory navigation Use of Use of The pushd, popd and dirs commands Command shortcuts are called aliases Created with the alias command Can be removed with the unalias command Are not persistent across sessions, but can be added to the /.bashrc le Clearing the screen
bash: prompt
Much more rich prompt capabilities than Bourne shell uses backslash-escaped character sequences
Lab 8
Estimated Time: 35 minutes
#!/bin/bash USER="$1" HOMEDIR=$(getent passwd "$USER" | cut -d: -f5) PUBDIR="${HOMEDIR}/public_html" mkdir "$PUBDIR" echo "<html><h1>Hello World</h1></html>" \ > "${PUBDIR}/index.html" chown -R "${USER}:" "$PUBDIR"
Run the script
$ ./mkwebpage.sh joe
Positional Parameters
Command line arguments in $0, $1, $2, . . . $0 is name of shell script (e.g. myscript.sh) $1 is rst argument, $2 is second, and so forth Number of arguments in $# List of all parameters in $@ Special shell variables
printf
Intended as an "advanced echo" Can be used like echo, but better suited for other tasks Especially useful for formatting numbers for reports
Doing Math
Simple expressions can be evaluated by the shell
$ foo=$((12*34)) $ echo $((56+$foo)) 464 Use the expr program within scripts for math AVG=$(expr \( $X1 + $X2 \) / 2) expr only does integer math Use perl, awk or bc for more advanced math $ pi=$(echo "scale=20; 4*a(1)" | bc -l)
Exit Status
Communicates whether a program successfully completed 0 means a program or command was successful 1 - 255 means a program failed somehow $? reports the exit status A script can use exit to report a specic exit status exit exit 1 echo $? The shell's logical AND (&&) and OR (||) operators also use return codes:
Conditional Statements
if then if then fi if then else fi if then elif else fi
Functions
Functions make code reuse easier Can add extra commands to the shell Default variable scope is global declare -f shows available functions unset -f function_name removes a function
Exit Status
Communicates whether a program successfully completed 0 means a program or command was successful 1 - 255 means a program failed somehow $? reports the exit status A script can use exit to report a specic exit status exit exit 1 echo $? The shell's logical AND (&&) and OR (||) operators also use return codes:
Lab 9
Estimated Time: 25 minutes
10
What is a Process?
A process is a launched program Associated with a process: process ID (PID) priority nice value memory security context environment le handles exit status
Process Lifecycle
Processes are organized in a hierarchy init rst process spawned by kernel with PID of 1 the only process directly launched by the kernel init will spawn child processes child processes spawn other children, etc. Processes can be created by two methods fork() create child duplicate of self exec() spawn completely new process that replaces parent fork() + exec() method for launching different process Process termination methods Normal termination via exit() Abnormal termination via abort() or uncaught signal
Process States
Processes can transition between states upon receipt of signals running currently being allocated CPU slices stopped still loaded in memory, but not running sleeping waiting for some event (ex. user input) un-interruptible sleep as the name suggests; usually caused when waiting for I/O zombie a terminated process whose resources have all been freed except for a PID and exit status
Viewing Processes
ps standard command to view process info
supports many options to modify output can emulate behavior of other Unix variants ps reads information from the /proc/ lesystem top similar to ps, but interactive refreshes display every 3 seconds by default can sort processes by various criteria such as CPU usage, memory, UID, etc. can send signals to processes gnome-system-monitor limited GUI top-like program KDE System Guard (ksysguard) GUI with extensive local & remote monitoring capabilities
Signals
Special message that can be sent to a process Processes can install signal handlers that catch signals and trigger some action Signals can have different meanings on different architectures Some signals cannot be caught or ignored and are processed by the kernel (ex. SIGKILL (9))
Using screen
Starting screen Commands Detaching and re-attaching to sessions Session basics
Advanced Screen
Session locking Split-screen Monitoring sessions Sharing screen sessions Default settings System-wide: /etc/screenrc Per user: /.screenrc
Lab 10
Estimated Time: 40 minutes
Regular Expressions
11
Regular Expressions
The building blocks of regular expressions are expressions that match a single character most characters, letters and numbers match themselves special characters are matchable as well "." (the period) matches any single character specify where the match must occur with anchors
RE Character Classes
Character classes, [...], match any single character in the list RE [0123456789] matches any single digit Some predened character classes [:alnum:] [:alpha:] [:cntrl:] [:digit:] [:lower:] [:punct:] [:space:] [:upper:] The - character denotes a range RE [[:alnum:]] equivalent to [0-9A-Za-z] Matches any single letter or number character
RE Quantiers
RE quantiers, control the number of times a preceding RE is allowed to match * match 0 or more times + match 1 or more times ? match 0 or 1 times {n} match exactly n times {n,} match at least n times {n,m} match at least n but not more than m times
RE Parenthesis
Parenthesis (RE) creating a new atom (RE)\non-zero digit storing values (RE1|RE2) alternation: RE1 or RE2
Lab 11
Estimated Time: 35 minutes
Text Processing
12
tr a-z A-Z
squeeze collapses duplicate characters commonly used to merge multiple blank lines into one
tr -s \n
deletes a set of characters commonly used to delete special characters
tr -d \000
Text Sorting
sort Sorts text
can sort on different columns by default sorts in lexicographical order 1, 2, 234, 265, 29, 3, 4, 5 can be told to sort numerically (by using the -n option) 1, 2, 3, 4, 5, 29, 234, 265 can merge and sort multiple les simultaneously can sort in reverse order often used to prepare input for the uniq command
Lab 12
Estimated Time: 10 minutes
13
Text Editing
Text Editing
Unix Revolves Around Text Text is robust Text is universally understood The only tool / program required is a text editor Remote administration possible over low-bandwidth connections Text Editors Many editors available, each with fanatical followings Pico/Nano, vi and Emacs are the most common $EDITOR and $VISUAL control default editor
Pico/GNU Nano
Pico Originally built into Pine Developed at the University of Washington (UW) GNU Nano A free replacement for Pico Emulates Pico functionality as closely as possible Advantages Simplicity in editing as primary goal Standard features like cut and paste; spell checking Disadvantages Not as powerful as many other editors
Pico/Nano Interface
Main Areas of Pico/Nano Top Line Editor Window Status Line Common Shortcuts Line Wrapping Happens automatically Can be avoided with -w
Pico/Nano Shortcuts
Common Shortcuts ^X eXit (quit), or close the current buffer ^O write Out (save) the current le ^G Get (display) the help screen ^W Where is (search for) a string ^\ search and replace (Nano only) Cutting and Pasting ^K cut a line ^U Uncut (paste) cut line(s)
vi and Vim
vi The Visual Editor Developed originally by Bill Joy for BSD UNIX Ofcially included in AT&T UNIX System V Available on all UNIX platforms Vim Vi IMproved Has signicantly enhanced functionality Includes a compatibility mode
Learning vi
Getting help Friends & Co-workers Books & Cheat Sheets :help Vim has extensive online help http://www.vim.org/
Basic vi
vi is Modal Insert Mode: keystrokes are inserted into the document Command Mode: keystrokes are interpreted as commands Basic Cursor Movement Commands hjkl Basic Editing Commands i a x dd Saving & Exiting :w :q :wq :wq!
Intermediate vi
Repeating Actions Undoing Changes Insert & Substitute Search & Replace Delete, Yank, & Put More Movement Commands
/usr/bin/gedit
Applications -> Accessories -> Text Editor Installed by default with GNOME
Lab 13
Estimated Time: 70 minutes
14
Secure Shell
Replaces unencrypted utilities rlogin, rsh and telnet rexec rcp Automates X11 authentication Supports tunneling of other protocols such as POP, IMAP HTTP PPP Supports user RSA/DSA keys for password-less logins
Transferring Files
Encrypted File Transfers sftp interactive le transfer scp non-interactive le transfer
ssh-agent
With public keys distributed, a user logs into the remote systems by providing the passphrase to unlock the private key The ssh-agent is a long-running daemon that caches decrypted private keys in memory ssh-add is used to add new keys to be cached ssh/sftp/scp will automatically use keys from ssh-agent Started automatically upon login to any supported graphical desktop environment
Lab 14
Estimated Time: 20 minutes
15
Lab 15
Estimated Time: 30 minutes
16
Messaging
wall
Similar to write, but sends message to all users on the system Effective in a pipeline
talk
Real-time keystroke at a time chat Works between Internet hosts as well
Pidgin Conguration
Accounts Manage Accounts Add, Modify, Delete Tools Preferences Interface, Logging, Network, Sounds Tools Plugins State Notication, History, Psychic, more...
Electronic Mail
Sendmail, Postx, and Exim: popular email servers / Mail Transport Agent (MTA) Command-line email clients / Mail User Agents (MUA) mail original, very simple client pine sophisticated, menu-driven client other command-line clients include:
elm mutt
GUI email clients Mozilla Thunderbird Email client from Mozilla Evolution Powerful GNOME Outlook clone Kmail Standard KDE mail client
Thunderbird
Email, USENET, and RSS Client for Linux Email Calendar (with Lightning extension) News Reader RSS Feed Reader
Lab 16
Estimated Time: 20 minutes
17
Printing
Ghostscript
Can be invoked on demand by lpd LPRng CUPS for printing to non-Postscript printers Ghostscript Utilities ps2ascii convert Postscript to ASCII ps2pdf convert Postscript to Portable Document Format ps2ps Postscript distiller makes a Postscript le simpler, and usually faster to print also includes ascii2ps and pdf2ps
mpage
Prints les with their text reduced in size so that several pages appear on one sheet of paper Input may be text or Postscript Useful for saving paper
Lab 17
Estimated Time: 20 minutes