1
|
- Richard C. Davis
UW CSE – 9/29/2006
- Lecture 2 – Linux and Shells
|
2
|
- If you missed it, let us know
- You’ll need one of your late-days
- If you had problems, let us know
|
3
|
- Getting the lay of the land
- Shell (bash)
- Directory structure, sense of place (pwd)
- Commands
- Viewing/Editing text files (emacs, cat, less)
- Manipulating Files/Dirs (mkdir, cp, mv, rm)
- Changing permissions (chmod)
- Lot of material fast
- Don’t worry, we’ll cover it all in greater depth
|
4
|
- Shell as an interpreter
- Shell model (Files, Users, Proceses)
- Shell language details
- Expansions
- History Access
- Aliases
- Command-line editing
|
5
|
- Interprets a language
- Language: program names, arguments
- Interpreter actions
- Runs program
- Passes arguments
- Prints output
- Waits for next command
- Program Capabilities
- Control filesystem
- Control devices: network (mail), display (windows)
- Launch other programs
|
6
|
- Files
- Users
- Processes
- We’ve already looked at files
|
7
|
- 1 file-system, 1 OS, 1 CPU, many users
- Users have
- Names (whoami, who)
- Passwords (/etc/passwd)
- Home directory (and quotas)
- Default shell (~/.bash_profile)
- Groups
|
8
|
- Permissions
- For every file and directory (ls –a)
- For user (chown), group (chgrp), and others
- Read, write, or execute
- Change with chmod
- Changing Permissions: chmod
- Superuser: root
|
9
|
- Process =3D running program
- “Applications” can have many
- Shell is a process (ends on exit)
- Default: shell waits for process to finish
- Great for ls
- Bad for emacs (need emacs&, or ^z bg)
- Commands for controlling processes
- jobs, fg, bg, kill, ps top
|
10
|
- Model =3D files, users, processes
- GUIs hide this
- Programmers need to get to it
- Where complexity comes from
- I/O Devices (network, display, keyboard, etc.)
- Language
- Designed for fast typing
- Designed for quick and dirty scripting
|
11
|
- Words and spaces → Call prog w/ args
- Types of words (not an exhaustive list)
- Built-ins (cd, type)
- Program names (ls, cat)
- Program arguments (-R, file.txt)
- Expansions (filename wildcards, braces)
- History access
- Aliases
- Pipes and redirections
- Shell and environment variables
- Programming constructs (if, loops, arrays, exprs.)
|
12
|
- Words can expand to multiple filenames
- ~uname → home directory of “uname”
- ~ → current user’s home directory
- * (by itself) → all files in current directory
- Except those starting with “.”
- * → matches 0 or more filename characters
- ? → matches 1 filename character
- [abc],[a-z] → any character in set, range
- [!a],[^a] → any character not in set, range
- This happens before passing to program
|
13
|
- When typing
- In scripts
- Helps if you don’t know what files are present
- cat * - to get all files in a directory
- What if you want special characters?
- Use quoting "*"
- Use escaping \*
|
14
|
- Create multiple strings from single string
- Not just for file names
- Example
- Typed: echo Garbage{In,Out}
- Expanded: echo GarbageIn GarbageOut
|
15
|
- List of all commands typed
- Way to see what you’ve done
- Shortcut for repeating previous commands
- Not so useful in scripts
- Syntax
- history
- !c – repeat last command starting with “c”
- !! – repeat last command
|
16
|
- Shorthand for frequently typed commands
- Different from variables (see these later)
- Syntax
- Define alias alias ll=3D“ls -l”
- View alias alias ll or type ll
- Remove alias unalias ll
|
17
|
- Most interesting yet to come!
- Pipes and redirections
- Shell and environment variables
- Programming constructs
- We’ll cover these in more detail later
|
18
|
- Shortcuts for navigating/editing commands
- Extremely helpful when typing
- Especially in terminals (e.g. when no arrow keys)
- No help in scripts
- Bash similar to emacs
- Interesting cases
- Up/Down arrows: access command history
- Tab: Filename completion (space in emacs)
- C-s: Stops displaying output until C-q
|
19
|
- Environment: files, users, processes
- Use shell to manipulate environment
- Shell language
- Commands and built-ins
- Program options and arguments
- Expansions, history, aliases
- Command-line editing
|
20
|
- Linux Pocket Guide
- Read
- p1-33 (Intro, Basics)
- p104-107 (Viewing Processes)
- p110-114 (Users and Their Environment)
- Skim
- p37-46, 60-63 (for commands used in lectures)
- Bash Reference Manual
- See “Computing Resources” on web page
- Skim sections 8.4.1-8.4.4 (Command-line editing)
|
21
|
- Combining Commands
- I/O redirection
- Logic expressions
- Quoting and escaping
- Variables
- Shell scripting introduction
|