課題番号:第11002号 研究背景 東南海・南海地震の発生リス …...課題番号:第11002号 y 研究背景 東南海・南海地震の発生リスク 東南海・南海地震の発生間隔
Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 ...
description
Transcript of Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 ...
![Page 1: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/1.jpg)
Joshua Xu / 许建华
中国上海 :电 话: 21-62470421,62470432地 址:上海市南京西路 1468 号东海电脑广场 3 号楼八层Email : [email protected]
新加坡:Tel : (65) 67760365Address: Blk432, #07-274 Clementi Avenue 3 120432
www.itlab.com.cn
CONFIDENTIAL
Unix/Linux Basic Course
Joshua Xu
高端软件培训[email protected]
![Page 2: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/2.jpg)
Objectives(5 days)
Unix/Linux Operating System BackgroundUnix/Linux Basic commandsFile and Directory ManipulationEditor(vi)User and Process managementShell programmingMakefileLinux Installation and Setup
![Page 3: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/3.jpg)
Agenda
上午 下午Unix/Linux 基本命令 文件系统VI(编辑器) 用户,进程管理,LINUX 安装SHELL 编程 SHELL 编程SHELL 编程 SHELL 编程SHELL 编程 Makefile
![Page 4: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/4.jpg)
Reference Book
![Page 5: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/5.jpg)
Unix
HistoryOther Compatible Unix Systems
![Page 6: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/6.jpg)
Linux
MINIX (PC Unix) 1991 (Andrew S. Tanenbaum)
Linux 0.021991
(Linus benedict Torvalds)Linux 2.x.x POSIX Compliant
to current version
![Page 7: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/7.jpg)
Linux VS Unix(1)
Linux is a real Unix, Functionality(Multi User, MultiTask,…)
POSIX compliant(from Ver2.x.x)System V & BSD compatible
![Page 8: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/8.jpg)
Linux VS Unix(2)
Open Operating System
Code
System CustomizingMinimum Hardware RequirementsSupport Multi File System(minix,ext,fat,…..)Software Resources and Powerful FunctionalityUnix is certified to be the robust system, Linux no
t yet…
![Page 9: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/9.jpg)
Unix VS Windows(1)
Hardware platform and Location
Reliability or Robustness
![Page 10: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/10.jpg)
Unix VS Windows(2)
User interface:ls option parameters
ls ls -al
Redirection and pipe
grep
find
Multi task
![Page 11: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/11.jpg)
Unix VS Windows(3)
Multi users
![Page 12: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/12.jpg)
Unix VS Windows(4)
Security
System know who you are
File and directory priority
![Page 13: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/13.jpg)
More About Unix/Linux
What can it do?
Production Line: Web Server, Mail server, Database Server
Program Development
Who should know Unix/Linux?
Unix administrator, System Manager, System Consultant
Oracle Administrator, Network Engineer, Program Developer
![Page 14: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/14.jpg)
Linux/Unix two FunctionsWhat are the two functions of OS? How to?
![Page 15: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/15.jpg)
Resource Management(1)
RAM, DISK difference
rams are paged
![Page 16: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/16.jpg)
Resource Management(2)
CPU
eg: ticket system
![Page 17: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/17.jpg)
Resource Management(3)
intangible resources’ management
opened files
sockets
Locks
![Page 18: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/18.jpg)
Be Aware of Case Sensitive!!!
![Page 19: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/19.jpg)
shutdownshutdown -[rhk] <time> warning
<time>:
hhmm[am|pm] MMDDYYYY + offset
MMDDYY JAN 20 2004 NOON MIDNIGHT
TEATIME now
Offset:n[minute,hour,day,week]
![Page 20: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/20.jpg)
telnet
telnet 192.168.100.1 [port]
Add item into file: c:/windows/system32/desktop/driver/hosts
![Page 21: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/21.jpg)
login
login: ( username)
password: (user’s password)
![Page 22: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/22.jpg)
Logout
Logout or exit or ^D
![Page 23: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/23.jpg)
Passwd
passwd
![Page 24: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/24.jpg)
uname
uname -a
![Page 25: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/25.jpg)
Exit
Exit or ^D
![Page 26: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/26.jpg)
Telnet
What’s the telnet?
a program a main function with a window
how does it work?
a client connected to a telnet server
a protocol
![Page 27: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/27.jpg)
ftp
ftp program, ftp command, ftp server
ftp client, ftp protocol
? --help
ls cd bin & asc get & put mget & mput bye
![Page 28: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/28.jpg)
Terminal
What’s the terminal?
What’s console, terminal, pseudo-terminal
tty0 tty1 pts/0
Echo $TERM
stty -a /stty all
stty erase ^? intr ^C kill ^U eof ^D swtch ^Z quit ^\
^J stty sane ^J
![Page 29: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/29.jpg)
logname
logname
![Page 30: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/30.jpg)
whoami
whoami
![Page 31: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/31.jpg)
who
Who
each user has an account, has a
password and a home directory
![Page 32: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/32.jpg)
datedate
date –u
date +%Y/%m/%d
to set date:
date MMDDHHMMCCYY ( this need root priority)
![Page 33: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/33.jpg)
calcal -y –j month year
![Page 34: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/34.jpg)
clear
clear
![Page 35: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/35.jpg)
echo
Echo
Echo –e abc“\a” -e:enable control char
\a alarm \c remove newline \n newline
\t tab \\ “\” \b backspace \f new page
\r linefeed \v vertical tab \nnn octal digit
![Page 37: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/37.jpg)
mesg
mesg -n –y
:you cann’t mask root’s message
mesg joshua
![Page 38: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/38.jpg)
![Page 39: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/39.jpg)
manman -n command
1 command 2 syscall 3 lib 4 special file
5 file format info …
![Page 40: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/40.jpg)
su
su
password: (root’s password)
![Page 41: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/41.jpg)
--------
What’s file?
File is the storage of data, program
File is the most important data structure of operating system
![Page 42: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/42.jpg)
The File Systems
![Page 43: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/43.jpg)
Path Name
Path name uniquely specify particular file or directory
Path name separated by “/”A “/” in the first position represents the
root directory
![Page 44: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/44.jpg)
ls(1)
ls
option: -a –A –l –v --help Note: file name rule no “/”
1 !@#$%&*()[]{}’ ” \ | / ; < > SPACE
2 case sensitive
3 .txt .doc .sh .html .pl .c .o .tar .gz .rmp
![Page 45: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/45.jpg)
File Attribute(1)
![Page 46: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/46.jpg)
File Attribute(2)
Type: - d l b c s p to see /dev/hda1 /dev/cdrom …
![Page 47: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/47.jpg)
File Permission
![Page 48: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/48.jpg)
chmod(1)
![Page 49: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/49.jpg)
Mode value
![Page 50: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/50.jpg)
chmod(2)
chmod a-w,o-rx *.cat
![Page 51: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/51.jpg)
Meta-Characters
* ? [adeg] [0-9a-zA-Z] [!a-zA-Z]
![Page 52: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/52.jpg)
ls(3)ls app*
ls [a-zA-Z]*
ls –al [!0-9]*
ls *.doc
ls fs??*s
ls /app*/usr? Conf.??.log
![Page 53: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/53.jpg)
pwd
pwd print working directory
![Page 54: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/54.jpg)
cdcd
cd ab*
cd ~
cd -
cd ~alice
cd ~/bin
CDPATH shortcut way to a directory
![Page 55: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/55.jpg)
Absolute Path name
A pathname uniquely identifies a particular file or directory by
Specifying its location
The slashes within pathnames separate object names
A slash in the first position represents the / (root) directory
![Page 56: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/56.jpg)
Relative Path Name
Specifies a file in relation to the current working directory are useful because they are shorter than absolute pathnames
Do not begin with a slash
![Page 57: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/57.jpg)
cat
cat file1 file2 file3 >file4
cat > file1
:generate one text file with cat
![Page 58: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/58.jpg)
Redirection & PIPE
What’s standard input output?
They are fd 0 1 2 (error)
/dev/null
< > >> |
Cat >&1 inout share the same fd
Cat > /dev/tty3
![Page 59: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/59.jpg)
cp
cp
![Page 60: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/60.jpg)
mv
mv
![Page 61: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/61.jpg)
mkdir
mkdir
![Page 62: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/62.jpg)
rm
Rm a*out*tmp
Rm file[0-9].tmp
Rm -i need confirm
-f ignore error report if file not exist
-R remove directory and its sub-directory
-d remove the directory even if not empty (root pri)
![Page 63: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/63.jpg)
ln(1)
![Page 64: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/64.jpg)
ln(2)
ln spacewar funky two items point to same file
ln /usr/harley/data1, /usr/harley/data2 /usr/addie/work
Or ln /usr/harley/data[12] /usr/addie/work
you let addie share your data
ln –s only a symbol, the file contain some characters
![Page 65: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/65.jpg)
touch
touch filename
How to process a file name with special letter?
![Page 66: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/66.jpg)
chown
![Page 67: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/67.jpg)
chgrp
![Page 68: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/68.jpg)
umask
umask
![Page 69: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/69.jpg)
grep(1)
![Page 70: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/70.jpg)
grep(2)Grep “sort” *.doc grep “sort it” *
Grep –c “48” data.f
Grep “48” data.f
Grep –n “48” data.f
Grep –v “48” d-ata.f
Grep “48 ” data.f grep ‘48\>’ data.f
Grep –i “sept” data.f
Grep ’48[34]’ data.f
Grep ‘^[^48]’ data.f
Grep ‘[Ss]ept’ data.f | grep 483
![Page 71: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/71.jpg)
grep(3)
Grep ‘^[^48]’ data.f
Grep ‘[Ss]ept’ data.f | grep 483
Grep ‘K…D’ data.f
Grep ‘[A-Z][A-Z]..C’ data.f
Grep ‘5..199[6,8]’ data.f
Grep ‘[0-9][0-5][0-6]’ data.f
Grep ‘^[0-9][0-5][0-6]’ data.f
Grep ‘4\{2,\}’ data.f
Grep ‘9\{3,\}’ data.f
![Page 72: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/72.jpg)
grep(4)
fgrep not support regular expression
egrep enhanced regular expression
egrep “([Ss]ome|[Aa]ny) one”
zgrep zipped files
![Page 73: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/73.jpg)
Regular Expression
^ $ [] [^] *
Enhanced regular expression:
“([Ss]ome|[Aa]ny) one”
![Page 74: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/74.jpg)
Find(1)find path expression action
options: -[i]name -type -link –perm
–size –user –atime –mtime –newer
operator -a –o ! ( )
.and. .or. .not. ( )
file type: f d c b l s p(pipe)
![Page 75: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/75.jpg)
Find(2)
find ~/. –name “*[aA]ug*” –print
find ~/. –name *[aA]ug* –print
find ~/. –name \*\[aA\]ug\* –print
![Page 76: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/76.jpg)
Filter commands(1)cat
grep
sort file1 >file2 output to same file, use –o option
cat file1 file2 | grep xxxx | sort | lp
-b ignore space and tab –r reverse order
-c(if already) –d(dictionary order) –f(case insensitive) –n(digit order)
–r(reverse) –u(same line occurs one time)
cut –c 1,8,10-20 file1
![Page 77: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/77.jpg)
Filter commands(2)
Sed to processing string
Tr -[cds] [string1] [string2] <file1 > file2 replace string1 with string2
Header -n
display head n lines, default 10 lines
Tail -n
display n tail n lines, default 10 lines
![Page 78: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/78.jpg)
wc
![Page 79: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/79.jpg)
diff
Find difference between files
diff –[bef] old-file new-file
![Page 80: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/80.jpg)
Device Files(1)
Block: Non_IDE interface CDROM: aztcd,bpcd,cdu31
a,cm260cd… IDE interface: hard disk,CDROM,etc.
Hd[num][partition num] SCSI interface: hard disk, CDROM,MO etc.
Sd[num][partition num] Floppy disk: fd[num][density]
fdaH1440,fbH1440
Two types of Device files : Block and Char
![Page 81: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/81.jpg)
Device Files(2)
Char: Ports
serial : cua0-- cua3 parallel : lp0-lp2
Terminal: tty pty console Taper : nrft0-nrft3 Null device :/dev/null /dev/Zero(for read) Symbol link : /dev/cdrom /dev/hdb
![Page 82: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/82.jpg)
fdformat
fdformat
![Page 83: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/83.jpg)
mkfs
mkfs
![Page 84: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/84.jpg)
mkdosfs
umask
![Page 85: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/85.jpg)
mount
mount /dev/cdrom /mnt/cdrom
mount /dev/floppy /mnt/floppy
unmount /dev/cdrom or /mnt/cdrom
![Page 86: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/86.jpg)
unmount
umask
![Page 87: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/87.jpg)
dd
Dd duplicate floppy disk
![Page 88: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/88.jpg)
df
df show file system informations
![Page 89: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/89.jpg)
du
du display file space usage
![Page 90: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/90.jpg)
Backup
tar –cvf d.tar /data
tar –czvf d.tar /data
tar –x d.tar
![Page 91: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/91.jpg)
gzip
gzip filename
![Page 92: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/92.jpg)
Exercises
![Page 93: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/93.jpg)
vi
Vi file1 Open file1, if file1 not exist, create it
Vi Open a new file and name it later
View file1 Open file1 as read-only
![Page 94: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/94.jpg)
Vi(states)
![Page 95: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/95.jpg)
Vi(move)
![Page 96: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/96.jpg)
Vi(insert)
![Page 97: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/97.jpg)
Vi(delete )
![Page 98: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/98.jpg)
Vi(undo , change )
![Page 99: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/99.jpg)
Vi(copy and paste )
Y line copy (or yy)
p paste under the current line
P paste above the current line
:1,2 co 3 append line 1 to line 2 toline 3
:4,5 m 6 move line 4 to line5 to line6
![Page 100: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/100.jpg)
Vi(save and quit )Save
:w save if the file already exist
:w file1 save as a new file file1
:wq save and exit (ZZ)
:q! ignore change and exit
![Page 101: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/101.jpg)
Vi(options ):set nu set line number (:set nonu)
:(number) go to line (number) :21 or 21G
G go to the end of file
/string forward search string
?string backward search string
N repeat
:1,$s/oldstring/newstring/g global string substitution
:r file1 insert another file
![Page 102: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/102.jpg)
Vi(exercises )
![Page 103: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/103.jpg)
--
![Page 104: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/104.jpg)
Network Basic
![Page 105: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/105.jpg)
Client-Server
![Page 106: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/106.jpg)
Networking Model
![Page 107: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/107.jpg)
Common Protocols and Applications
![Page 108: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/108.jpg)
TCP/IP Networking Addressing
![Page 109: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/109.jpg)
Networking Services
![Page 110: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/110.jpg)
TCP/IP Networking Addressing
![Page 111: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/111.jpg)
Important files and utilities
Ifconfig
ping
finger
Netstat - rn
traceroute www.itlab.com.cn
![Page 112: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/112.jpg)
--
useradd userdelProhibit temp usersfinger usernamegroupadd –g groupdel
![Page 113: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/113.jpg)
useradd
Useradd userid
Passwd userid
![Page 114: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/114.jpg)
userdel
userdel
![Page 115: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/115.jpg)
Prohibit temp user
passwd –l username
passwd –u username
![Page 116: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/116.jpg)
finger
finger username
![Page 117: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/117.jpg)
Groupadd
groupadd –g
![Page 118: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/118.jpg)
Group delete
groupdel
![Page 119: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/119.jpg)
telnet
![Page 120: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/120.jpg)
ftp
![Page 121: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/121.jpg)
rlogin
![Page 122: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/122.jpg)
rusers
![Page 123: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/123.jpg)
--
进程管理 ps –acdef kill -9 定时执行 at Batch crontab
![Page 124: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/124.jpg)
Ps(1) ps (same group)
-a (other), -e(all)
querying:
-C httpd G gid U user
g (session title, ) p (ID) t (tty) u (uid)
format:
-f(full) j (working style) l(long) o(user defined) y(no tag) j(working control)
l (long) o(set user defined format)
s(signal format) u(user guidance) v(virtual memory)
![Page 125: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/125.jpg)
Ps(2) process status: D uninterruptible sleep, usually IO R runnable process S sleeping T stopped or traced Z zombie process W no resident page < high priority process N low priority process L memory locked process
![Page 126: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/126.jpg)
Ps(3) Process attribute: USER
%CPU percentage occupation
%MEM
SIZE
RSS (resident size may be smaller than SIZE
TTY
STAT status
START start time
TIME time executed
FLAGS only administrator need know
UID PID PPID PRI (time slice) NI (priority)
WCHAN kernel function name when process sleeping
![Page 127: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/127.jpg)
kill
Kill -9
![Page 128: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/128.jpg)
nice
• nice
• renice
![Page 129: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/129.jpg)
nohup
Nohup results backend process running without interrupted
Nohup command & (>nohup.out)
![Page 130: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/130.jpg)
jobs
![Page 131: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/131.jpg)
fg
fg %N job number N
%string command begin with the string
%?string command contain the string
%+ last backend process
%% same as above
%- second last backend process
![Page 132: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/132.jpg)
bg
Bg command brings jobs to backend
![Page 133: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/133.jpg)
at
1.
At 21:00
At> command
^D
2. Echo command | at now + 2 minutes
![Page 134: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/134.jpg)
batch
Batch is at similar command, the command will be run at system leisure time
![Page 135: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/135.jpg)
CrontabVi Cronjobcommandscript
<minute> <hour> <day> <month> <weekday> <command>
30 21 * * * action
45 4 1,10,20 * * action
0,30 18-23 * * * action
Vi usercron
Crontab usercron
Crontab –l – e –r
![Page 136: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/136.jpg)
--
Shell programming
![Page 137: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/137.jpg)
KernelManage devices, memory and processes
Controls the functions between the system programs, utilities and the system hardware
Manage swap space, daemons, file systems and other functions
![Page 138: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/138.jpg)
What’s the shell
Shells: chsh -l
Which kind of Shell we are using?
![Page 139: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/139.jpg)
Who needs know it?
Unix/Linux administrator
DBA
Programmer
![Page 140: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/140.jpg)
BASH
Echo $SHELL
Whereis bash
Which bash
![Page 141: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/141.jpg)
Change shell
Usermod –s shellname username
Chsh -l
Chsh –s shellname username
![Page 142: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/142.jpg)
Shell command
Command1;command2;command3
Command1;(command2;command3);command4
![Page 143: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/143.jpg)
Shell Script
A file contains shell commands
#!/bin/bashCal 1 $1Cal 2 $1Cal 3 $1
![Page 144: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/144.jpg)
Sub shell(1)What’s sub shell?
Inherited: Current directory Environment variables File descriptor 0,1,2 Ignored signal
Uniherited: User defined variables without exporting ignored signal
![Page 145: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/145.jpg)
Sub shell(2)How to understand sub shell:
1 environment variables
2 Delcared variable with –x option
3 Print SHLVL in script
![Page 146: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/146.jpg)
Define a shell variable
DISPLAY=192.168.0.10:0.0
X=12
echo $DISPLAY $X
echo ${DISPLAY} ${X}
Using declare statement
declare –a –f –i –r –x -F
![Page 147: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/147.jpg)
Variable type
Val1=12 val2=5
Result1=val1*val2
Echo $result1 default is string
Declare –i val3=12 val4=5
Declare –i result2
Result2=val3*val4
Echo $result2
![Page 148: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/148.jpg)
Un-define shell variable
Unset Display
Unset X
![Page 149: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/149.jpg)
Array
Names[0]=alice Names[1]=tom Names[2]=jimmy
Names=(alice tom jimmy) Names=(alice [2]= tom jimmy)
${Names[0]} ${Names[@]}
${#Names[0]} ${#Names[@]}
![Page 150: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/150.jpg)
All kinds of Variable
System defined Environment variable
env
Built-in variable
IFS RANDOM (0-32767) $@ $* $# $? $$ $+ $- $<
User defined variables
Command line parameter $0 $1 $2 $3 $4…
![Page 151: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/151.jpg)
Math operator and expressions+ - * / % << >> & | ~ ! ^
< > <= >= == != && ||
$((3>2))
$(($RANDOM%10+1))
$((3>2)||(4<=1)))
If true return 1 otherwise return 0
Echo “only $(((365-$(date +%j))/7)) weeks until the New Year”
B#N
Let intvar=expression
![Page 152: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/152.jpg)
references
For string: “ ” ‘ ’ { } b{ed,olt,ar}s ` `
![Page 153: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/153.jpg)
String operation(1)• secure variable exists• Set default value• Capture undefined variable error• Delete sub-string of pattern string ${varname:-word} ${varname:=word} ${varname:?word}${varname:+word}${varname:offset}${varname:offset:length}
![Page 154: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/154.jpg)
String operation(2)• Str1=str2
• Str1!=str2
• Str1<str2
• Str1>str2
• -n str str not null
• -z str str is null
![Page 155: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/155.jpg)
String operation(3)
${variable#pattern} ${variable##pattern}${variable%pattern} ${variable%%pattern}${variable/pattern/string}${variable//pattern/string}
![Page 156: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/156.jpg)
function function functionname{
shell command;}Or
function functionname(){
shell command;}
![Page 157: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/157.jpg)
Return and exit return
return N
return only be used in function and source executed script
exit
exit N
other statements:
source break continue, eval,exec,export,
readonly, set, shift, trap, unset
![Page 158: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/158.jpg)
Running Shell Script
chmod a+x abc abc Source ./abc Source ./abc &
eg #!/bin/bash${x:?’x undefined’}echo “exit with notice”
interactive mode
![Page 159: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/159.jpg)
Script location Params
A shell script accepts parameters entered in command line.
#/bin/bash
Cal 1 $1
Cal 2 $1
Cal 3 $1 shift , $0 no change
![Page 160: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/160.jpg)
Expression testtest <logic expression>
[ 3 -gt 2 ]
If true return 0 otherwise return 1
![Page 161: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/161.jpg)
Test operators[! Expression]
[ expression1 –a expression2 ]
[ expression1 –o expression2 ]
[ file existence ]
math operators: -lt -le –eq –ge –gt –ne
[ \(3 –gt 2\) -o \( 4 - le 1 \) ]
note: [ expression ] is equivalent to
test expression
![Page 162: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/162.jpg)
File Attributes -d file file exists and is a directory-e file file exists-f file file is a regular file–s file exists and not empty -r–w –x access priority–O owner -G Group ID match my GIDfile1 –nt file2 file1 is newer than file2file1 –ot file2 file1 is older than file2
![Page 163: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/163.jpg)
Command substitution$(command)
The old style command substitution:
echo “Today is `date`”
Bash new style is
echo $(date)
![Page 164: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/164.jpg)
Flow control(for) #!/bin/bash
for I in 1 2 3 cal $I 2003done
#!/bin/bashfor I cal $I 2003doneabc 1 2 3
![Page 165: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/165.jpg)
Running Shell Script
chmod a+x abc abc Source ./abc Source ./abc &
![Page 166: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/166.jpg)
Script location Params
A shell script accepts parameters entered in command line.
#/bin/bash
Cal 1 $1
Cal 2 $1
Cal 3 $1 shift , $0 no change
![Page 167: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/167.jpg)
Read statement
Read varname
read into varname from input
Read varname < file
read into varname from file1
![Page 168: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/168.jpg)
Flow Control(case)#!/bin/bash
case $1 in
China ) echo Beijing
USA ) echo Washington
British ) echo London
France ) echo Paris
* ) echo Out of my knowledge
esac
capital China
![Page 169: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/169.jpg)
Flow Control(if)if condition
then statement;e
[elif conditionthen statement…]
[else statement]
fi#/bin/bashif test –w /dev/lpthen echo Printer is readyelse echo Printer is not readyfi
![Page 170: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/170.jpg)
Flow Control(while until)while
do
done
until
do
done
![Page 171: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/171.jpg)
Flow Control(<<here)command << label
…
…
label
#/bin/bash
grep $1 <<!
Huang w (21)81828888
Zhang QF (21)67678787
!
![Page 172: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/172.jpg)
Customizing user env.bash_profile, .bashrc
.bash_login, .profile
.bash_logout
If .bash_profile not exist, find .bash_login,.profile respectively .bash_profile only read by login shell
.bashrc read by .bash_profiel or sub bash shell command
![Page 173: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/173.jpg)
alias
Alias lf=‘ ls –F’
Alias printall=‘pr * lpr’
Alias cdvoy=‘cd ipp/demo;animation/voyager ’
Alias del=rm -i
![Page 174: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/174.jpg)
options
Set –o vi
Ignoreeof mask ^D single ^D operation
Noclobber mask “>>”
Noglob mask meta-characters
Nounset no unset
![Page 175: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/175.jpg)
PS1,PS2,PS3,PS4PS1 command line prompt
eg: PS1=‘\u@\h \w\$’
PS2 wait string for further input
PS3 select statement prompt PS4 debug prompt
![Page 176: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/176.jpg)
I/O(1)
> 1> cat >Phones grep “John” Phones >Phone.bak
< 0< cat <Phones grep “John” <Phones tr –s “ ” <Phones
> 2>
![Page 177: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/177.jpg)
I/O(2)
Sort 0< students 1>students.sorted 2>sort.err
Cat lab1 lab2 lab3 2>cat.errors 1>&2
Cat lab1 lab2 lab3 1>cat.output 2>&1
>> append data to file
Cat lab1 lab2 lab3 1>>filename 2>>error.log
![Page 178: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/178.jpg)
I/O(3)
Command1 | command2 |command3
![Page 179: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/179.jpg)
I/O(4)
>|file n>|file <<label <>file
n>>file
&>file 1 2 to file
<&- close 0
>&- close 1
![Page 180: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/180.jpg)
Command processingStep1 –step8 :
step 1: if open key word encountered, continue
if a close key word encountered, error
step 2: is alias, replace it, go to step 1
step 3: { } expands
step 4: ~ substitution
step 5: parameter substitution
step 6: command substitution
step 7: math expression calculation
step 8: keyword recognition
step 9: meta-character expands
step 10: run
![Page 181: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/181.jpg)
Process processing(1)
ps
Jobs
fg %N job number N, suspended process resumes
%string command begin with the string
%?string command contain the string
%+ last backend process
%% same as above
%- second last backend process
![Page 182: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/182.jpg)
Process processing(2)
Signal kill –l to see all the signal
Control key signal ^C intr ^\ terminate ^S ^Q ^Z
Trap
Eval
![Page 183: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/183.jpg)
waitting
In a shell script:
alice &
hatter
wait
: script running will wait until alice finished
![Page 184: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/184.jpg)
Shell debugging
Bashdb
Set –o noexec verbose xtrace
![Page 185: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/185.jpg)
Example#!/bin/bash
trap "nice_try" 2 3 15
TTY=$(tty)
nice_try()
{
echo "nice try, the terminal stays locked"
}
SAVEDSTTY= `stty -g` 1> /dev/null 2>&1
stty -echo
echo -n "Enter your password to lock $TTY"
read PASSWORD
clear
while :
do
read RESPONSE < $TTY
if [ "$RESPONSE" = "$PASSWORD" ];
then
echo "unlocking.."
break
fi
echo "wrong password and terminal is locked"
done
stty echo
stty $SAVEDSTTY > /dev/null
![Page 186: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/186.jpg)
Awk(1)awk –F”x” ‘command’ input-file
mode and action
To see grade.txt
awk ‘{print$0}’ grade.txt
awk ‘{print$1}’ grade.txt > wow
awk ‘{print$1”,”$2}’ grade.txt |tee wow
awk ‘BEGIN {print”Name\tBelt\n--------------------”}\
{print$1”\t”$4} END{print”-------------------\n\
end of printing”} grade.txt
![Page 187: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/187.jpg)
Awk(2)awk ‘{if($3~/Brown/) print$0}’ grade.txt
awk ‘$3==“48” {print $0}’ grade.txt
awk ‘$3!=“48” {print $0}’ grade.txt
awk ‘$4!~/Brown/ {print $0}’ grade.txt
< > >= <= ==
/[Gg]reen/ /^…a/ /(Yellow|Brown)/
/ && / / || /
![Page 188: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/188.jpg)
Awk(3)Built-in variables :
AGC,ARGV,ENVIRON,FIELNAME,FNR,FS,NF,OFS,ORS,RS
Operator:= += *= /= ^= ? || && !< <= == != >=
+ - * / % ^++ --
![Page 189: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/189.jpg)
Awk(4)Add Fields:
awk ‘if($6<$7) {$8=$7-$6;print $1”,”$8}’ grade.txt
File Length calculation:
ls –l | awk ‘/^[^d]/ {print $9”\t”$5}{tot+=$5}
![Page 190: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/190.jpg)
Awk(5)Built-in string operator:
gsub(r,s) awk ‘gsub(/4842/,4899) {print $0}’ grade.txt
awk ‘{print index(“Bunny”,”ny”)}’
gsub(r,s,t),index(s,t),length(s)
match(s,r),split(s,a,fs),sprint(fmt,exp)
sub(r,s) substr(s,p) substr(s,p,n)
![Page 191: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/191.jpg)
Awk(6)mask
\b \n \f \r
![Page 192: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/192.jpg)
Awk(7)printf
- Width .prec
%cdefgosx
awk ‘{printf “%c\n”,$0}’
awk ‘{printf “%-15s”,$0}’
![Page 193: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/193.jpg)
Awk(8)Array:
awk ‘BEGIN {print split(“123#456#678”,myarray,”#”)}’
for (element in array) print array[element]
![Page 194: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/194.jpg)
Example
Rm $(ls –l |awk ‘ { if ($5 >=1000000) print $9 }’ )
If condition is true then print, why is not the “false”?
![Page 195: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/195.jpg)
sedsed –e ‘/foo/d’ myfilesed –e ‘/50d’ myfilesed –e ‘/50,$d’ myfilesed –e ‘s/foo/bar/’ myfilesed –e ‘s/foo/bar/g’ myfilesed –e ‘s/foo/s/***/’ myfile
:do not redirect to >myfilesed –f {command; } <file1 >file2Other command: =(lineno),w(write address),q
(quit)
![Page 196: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/196.jpg)
--
Make and makefile
![Page 197: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/197.jpg)
GCC(G++)Gcc is a common C compiler from GNU
C program compiling four steps: Preprocessing Compiling Assembly Linking
![Page 198: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/198.jpg)
GCC OptionsGcc -o –g –c –O –O2 –I –L –l –static –shared -DDEBUGeg: gcc –DDEBUG …In file.c #ifdefine DEBUG loginfo(char * str) {.. };#endif ? Explain what is preprocessing man gcc for detailed usage
![Page 199: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/199.jpg)
GCC(G++)Gcc is a common C compiler in Linux
C program compiling four steps: Preprocessing Compiling Assembly Linking
![Page 200: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/200.jpg)
makeWhy make?
1
2
![Page 201: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/201.jpg)
makefileMake
Default : GNUmakefile, Makefile, makefile
make –f makefile
Make –d display debug info
Make –h --help
Make –n only parse the command
Make –s no info displayed
![Page 202: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/202.jpg)
example
power: main.o input.o compute.o
gcc main.o input.o compute.o –o power -lm
main.o: main.c main.h input.h compute.h
gcc -c main.c
input.o: input.c input.h
gcc –c input.c
compute.o: compute.c compute.h
gcc –c compute.c
![Page 203: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/203.jpg)
ruleSUFFIXES : .o .c .s.c.o:
$(CC) $(CFLAGS) –c $<.s.o:
$(AS) $(ASFLAGS) –o $@ $< #power:main.o input.o compute.o
gcc main.o input.o compute.oMain.o : main.h input.h compute.hInput.o : input.hCompute.o : compute.h
![Page 204: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/204.jpg)
macro
Pre-defined symbols
$@(target name) $*(%.*)
$?(newer dependency files)
$<(first depen..) $^(all depen..list)
![Page 205: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/205.jpg)
virtual target
Some target does not exist, you do not have to create it, but some actions can be taken
![Page 206: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/206.jpg)
Special targets
• .defaults
• Ignore
• .PHONY
• .DILENT
• SUFFIXES
![Page 207: Joshua Xu / 许建华 中国上海 : 电 话: 21-62470421,62470432 地 址:上海市南京西路 1468 号 东海电脑广场 3 号楼八层](https://reader033.fdocument.pub/reader033/viewer/2022061315/5681553b550346895dc30fed/html5/thumbnails/207.jpg)
LINUX 安装和启动对硬件的要求 (1G Linux 7.2, depends …)分区 (ext2, swap)安装引导过程SetupX WINDOW