Monday, April 9, 2012
SA class 2
Kernel and Shell
Hardware => kernel => shell => you
shell: +-=> Fetch command => analyze => execute -+
| |
+-----------------------------------------------------------------+
startup files
sh
/etc/profile login shell, system wide
~/.profile login shell
ENV always
csh
/etc/csh.cshrc always , system wide
/etc/csh.login login shell, system wide
~/.cshrc always
~/.login login shell
~/.logout logout shell
/etc/csh.logout logout shell, system wide
tcsh
~/.tcshrc login shell
bash
/etc/profile
~/.bash_profile
~/.bash_login
~/.profile
~/.bashrc
BASH_ENV
Shell special characters
Reduce typin as as possible, be lazy zzZ
* Match any string of characters
? Match any single alohanumeric characters
[...] Match any single char within []
[!...] Match any single char not in []
~ Home
# this is a comment
; command separator
&& execute first one and execute second if first one success (exit
code: 0)
|| execute first one and execute second if first one fail (exit code:
!= 0)
\ Excape char or command continueation indicator
& background execution
shell ENV variables:
control shell behaviors
to dump them:
"env" command
To get value:
$variable_name or ${varible_name}
Useful env variables
sh / csh what it is
HOME / HOME home
MAIL / MAIL mailbox
PATH / PATH search path
PS1 / prompt prompt string
PS2 / prompt2
/ prompt3
IFS / internal field separators
/ history Number of history commands
variables and string quotes
assignment:
sh: var=value csh: set var=value
get variavle:
$var or ${var}
substitution stdout `cmd`
'string' without substitution
"string" with substitution
Assignment:
local variables
sh: my=test csh: set my=test
global variables
sh: export my csh: setenv my test
shell I/O:
stdin 0
stdout 1
stderr 2
user defined: 3~19
redirection:
change the direction of shess I/O
creat files
append to files
use existing files as input
merge output streams
use part of shell command as input
Usage:
> open the following file as stdin
< open the following file as stdout
>> append to the following file
>& merge stdout with stderr
| pipe stdout into stdin
PIPE:
pipe pipe
stdin => cmd1 ==> cmd2 => stdout
\ \
->stderr ->stderr
build-in shell commands:
alias / cd / echo / eval / exec / exit
jobs / kill / fg / bg / set / export
hash / umask
Useful commands:
passwd, chsh, chfn, chpass
pid: ps, top
directory: ls, mkdir/rmdir
file: cp/mv/rm
Email reader: mutt
News reader: tin
Connecting: ssh/telnet
Manual: man, info
Editor: vim, joe, ee, …etc.
File Transmittion: ftp, ncftp, lftp, scp, wget, curl
Compilers: gcc, g++, javac
Scripting: perl, php, ruby, python
login/exit/logout/screen
=================================
single user mood => read only
read only
mount -u /
mount -a -t ufs
swapon -a
how to shut dowm or reboot:
Turning off the power <--- don't do that
shutdown -h # halt
shutdown -r # reboot
kill -TERM 1 # kill init
time format (+m):
hh:mm # for Linux
yymmddhhmm # for FreeBSD
power off
shutdown -p now
=================================
Installing Apps
Package: (Pre-built)
Linux: rpm, yum, dpkg
FreeBSD: pkg_add, pkg_delete, pkg_info, pkg_version
Source:
Tarball
tar zxvf source.tar.gz
cd source
./configure [options]
make
make install
Three technologes:
Packages Pre-built!
Ports /usr/ports/.....
Tarball Fetch from internet
pkg_add # add a package
pkg_dd pkg_name
pkg_add -r pkg_name # while you don't know the name
pkg_info # see some infomation, btw, use it with grep :)
pkg_delete #delete a package
pkg_delete pkg_name
How to use ports:
to find where the application is
$ whereis application_name
goto its directory
$ cd /usr/ports/.../...
install it! Ports will fetch the tarball and compile the source code
make && make install clean
portsnap
/etc/portsnap.conf
=> SERVERNAME=portsnap.tw.FreeBSD.org
sudo portsnap fetch extract update # update your ports
note: use 'rehash' command after install an application # for tcsh
=================================
X window
X can be called X, X11, X window
client-server model
'Project Athena' @ MIT in 1984
Architecture:
client: request display service
server: provide display service
communicated with X Protocol
Client:
An application written in X libraries (e.g. Xlib)
Request service
Receive events from X server
Server:
Runs locally and accepys multiple X clients
X protocol:
local and network based computing look and feel the same
X11 implementation:
XFree86
Xorg
window manager:
A special X Client provides certain look-and-feel window in front of you
Background desktop theme
control windows' behaviors
size: resize, minimize, maximize
position: overlap, move
Examples:
Gnome, KDE, Xfce ...
xdm
X Display Manager
x11 forwarding
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment