Transcript osd03

CS 6560 Operating System
Design
Lecture 3:Tour of GNU/Linux
More on Kernel Compiling
• Configuration:
– make defconfig
– make menuconf
– Looking at .conf
• Making the initrd
– Documentation on initrd and mkinitrd
– Dealing with incompatibilities
Some references
• An introduction to Linux:
– http://tldp.org/LDP/intro-linux/html/
• An introduction to the Bash shell
– http://tldp.org/LDP/Bash-BeginnersGuide/html/index.html
Tour of Linux
•
•
•
•
•
•
•
•
•
Accounts
Logging in and out
Getting help
Shells: bash
Common commands
Editors
Compiler: gcc
Make
Services
Getting Help
•
•
•
•
man
info
Documents directory of the source
google
Shells
• Why have shells?
– Giving commands (requests) to the system
• What is a shell?
– Command interpreter
– Basic commands: internal and external
• Internal:
–
–
–
–
Control structures (if, while, for, break, continue, exit)
Job control (fg, jobs)
Current status (cd, pwd, )
I/O (read, echo, printf)
• External – loaded into new process
• What shells are available?
– sh, csh, tcsh, zsh, bash, rc, etc.
Bash Shell Syntax
•
•
•
See “info bash”
Everything is broken into words first
Shell variables
–
–
–
–
•
Parameters
–
–
•
variables are stored as strings
variables can be assigned values
use of $ to get value
export: shell -> environmental variable
$1, $2, $*
set, unset, shift
Quoting and expanding
–
Several types of expansions:
•
•
•
•
•
•
–
•
single and double quotes, escaping with backslash
Pipes, filters, redirection to form pipelines
–
•
Brace Expansion: Expansion of expressions within braces.
Tilde Expansion: Expansion of the ~ character.
Shell Parameter Expansion: Expansion of variables to their values.
Command Substitution: Using the output of a command as an argument.
Arithmetic Expansion: Using arithmetic in shell expansions.
Filename Expansion: wild cards and square brackets
| > < >>
Control structures: while, for, until
The Shell as a programming
environment
• Creating a script
• #! notation
• Executing the script
– sourcing with . or source
– invoking by name (must set the permissions)
External Commands
• File and directory manipulation
– cp, rm, chmod, mkdir, rmdir, ls
• Filters
– grep, sort, cat, head, tail, cut, paste, od, tr, pr, wc
• Program development
– Gcc, make
• Text processing
• System administration
Some Common External Commands:
file and directory manipulation
ls
List directory entries
cd
Change directory
pwd
Print path of current directory
chmod
Change permissions
mkdir
Create a new directory
rmdir
Remove a directory
mv
Move a directory entry
rm
Remove a directory entry
Some Common External Commands:
text manipulation (filters)
cat
Concatenate multiple files to standard output
more
Paged output to standard output
less
Fancier version of more
head
Show the first few lines of a file
tail
Show the last few lines of a file
grep
Search files for a pattern
cut
Cut columns of text from a file
od
Octal dump a file (also: hex,char,binary)
sort
Sort a file
tr
Translate a file character by character
pr
Format a file for printing
wc
Count words, lines, characters
Unix Permissions
• Each file and directory has an owner and a group
membership
• Permissions are organized by user (owner), group, and
others
– u = user, g = group, o = others
• Permissions consists of read, write, and execute for each
type of user
– r = read, w = write, x = execute
• Permissions can be viewed with the ls command and
changed with the chmod command.
• Permissions meanings are different for regular files than
for directories (see man page for ls and chmod).
• Examples in class
Editors
• vi (now vim)
• emacs
• pico
Getting Organized
• Use permissions for privacy
• Organize your work in directories
Program Development
•
•
•
•
Shells
Perl
C: gcc
Use of make (see info make)
The proc file system
• Shows a view of the kernel in terms of files
• For details see
– man proc
– /usr/src/linux/Documentation/filesystems/proc.txt
• Assignment #2 - using proc to get
information about a machine
Services
• Many processes run in the background taking care
of things such as printing and logging people in.
• Vmware-tools is an example service.
• Centos has a GUI interface to its service through
the system configuration menu.
• Services can be controlled directly from command
lines and scripts located in /etc/init.d and
referenced from /etc/rc.d according to runtime
level. - see the scripts for vmware-tools