Title: UNIX ??
1UNIX ??
2??
- 1. UNIX ??? ??
- 2. ?? ??
- 3. vi ??? ??
- 4. Shell I
- 5. Shell II
- 6. Process Control
- 7. Shell Programming I
- 8. Shell Programming II
- 9. ??? ?? ??
31. UNIX ??? ??
- ? ?
- 1. UNIX? ??? ????.
- 2. Login ? Logout? ? ? ??.
- 3. UNIX ??? ??? ????.
- 4. ??? ???? ??? ? ??.
- 5. ???? ????? ??? ? ??.
4UNIX ??
- ????
- UNIX ????
- ??? ??? ?? ?? (Multi-tasking)
- ?? ??? ?? (Multi-user)
- ?? ???? ???
-
5UNIX ?? (??)
6Logging In and Out
- login user1 Login
- Password
- Login message
- date Do work
- other commands
- exit or ltCtrlgtd Log out
7Command Line ??
- ??
- command -option argument
- ?
- date
- Wed Mar 31 203332 JST 1999
- ls
- dira dirb f1 f2 prog1 prog2
- ls -F
- dira/ dirb/ f1 f2 prog1 prog2
8Online ???
- ??
- man -X command
- X Manual Page Section number
- Section ??? ?? (HP-UX)
- ?
- man date
- man passwd
- man 4 passwd
1User Commands 1mSystem Maintenance Commands
(Section 8) 2System Calls 3Functions and
Function Libraries
4File Formats 5Miscellaneous Topics 7Device
(Special) Files 9Glossary
9?? ??? (I)
- id ??? ID ? ?? ID ??
- id
- uid601(user1) gid600(class)
- w ??? botting ??, load, login ??? ??(??)??
- w
- 900pm up 8 days, 731, 4 users, load
average 0.08, 0.03, 0.02 - User tty login_at_ idle JCPU
PCPU what - root console 246pm 12904
-sh - user3 pts/0 259pm
w - who ?? login ? ??? ?? ??
- root console Mar 24 1446
- user3 pts/0 Mar 31 1459
- who am i Local ???? ??? ??? ?? ??
- user3 pts/0 Mar 31 1456
10?? ??? (II)
- date ??? ??? ??? ??
- date
- Fri Mar 26 145742 JST 1999
- passwd Login Passwd ??
- passwd
- Changing password for user1
- Old password
- New password
- Re-enter new password
11?? ??? (III)
- hostname ???? ??? ??
- hostname
- ich01
- uname ???? ??? ????? ?? ?? ??
- uname -a
- HP-UX ich01 B.10.20 U 9000/869 1426594321
unlimited-user license - echo ??? ??
- echo how are you
- how are you
- banner ? ??? ??
- banner hi!
-
-
-
-
-
-
-
12?? ??? (IV)
- write login ?? ?? user? terminal ? ???? ??
- write user2 tty0p4
- Hi ltReturngt
- Nice to meet you! ltReturngt
- ltCtrlgtd
- mesg ??? ?? ??/?? ??
- mesg
- is y
- mesg n
- mesg
- is n
- mail mail ??
- mail user1 user1 ?? ??? ??
- see you again ltCtrlgt d
-
- mail ?? ??? ??
13?? ??? (IV)
142. ????
- File System Hierarchy
- File System ?? ???
- ???? ???
- ?? ??/??
15File System Hierarchy
16???? .vs. ???? (1)
- ????
- ???? ????? ??? ???? ??
- ????? ? ?(??)?? ?? ( / ? ??)
- ????? ????/???????? ???
- ????
- ????? ?????? ?? ( / ? ???? ??)
- ????? ???? ??
- ??????
- ??? ????(? ????) ??? ???? ???? ????
- Dot (.) ?? ????
- Dot Dot (..) ?? ???? ?? ?? ?? ????
17???? .vs. ???? (2)
18File System ?? ???
- pwd ?? ????? ???? ??
- ls ?????? ??/???? ?? ??
- cd ???? ??
- find ??? ??
- mkdir ???? ??
- rmdir ???? ??
19File System ?? ??? I
- ls dir ????? ??? ?? (List Contents of a
Directory) - -a ?(.)?? ???? ?? ???? ?? ?? ??
- -d ???? ?? ??
- -l ??, ??, ???, ???, ??, ?? (byte), ???, ??
- -F ?????? ?? (/) ??, ???? ???? ??
- -R ???????? ????? ??
- ?
- ls
- f1 f2 memo
- ls -F
- f1 f2 memo/
- ls -aF
- ./ .exrc .profile f1
memo/ - ../ .login .sh_history f2
- ls -F /home
- user1/ user2/ user3/
20File System ?? ??? II
- pwd ?? ?? ????? ??(Present Working Directory)
- pwd
- /home/user1
- cd ???? ?? (Change Directory)
- pwd
- /home/user3
- cd memo pwd
- /home/user3/memo
- cd ../../ pwd
- /home
- cd /tmp pwd
- /tmp
- cd pwd
- /home/user3
21File System ?? ??? III
- find ??? ??
- ?? find start_dir -name filename start_dir ??
???? ?? ??? filename ? ??? ???. - start_dir ???? ??. ?? ????? ????? ??
- ?
- find . -name .profile
- ./.profile
- find / -name f1
- /home/user3/memo/f1
- /home/user3/f1
- find . -name core
22File System ?? ??? IV
- mkdir, rmdir ????? ??, ????? ??
- ?? mkdir -p dir_pathname(s) ????? ??
- -p ??????? ?? ?? ??
- rmdir dir_pathname(s) ????? ???
- ?
- lsf
- f1 f2 memo/
- mkdir fruits/apple
- mkdir cannot access fruits No such file or
directory - mkdir -p fruits/apple
- rmdir fruits
- rmdir fruits Directory not empty
- rmdir fruits/apple fruits
23File ? ??
- Regular Files (????)
- 1. ???, ???, ???? ?? ??
- 2. ls, man, date ?? ????? ????
- Directories (????)
- ?? ?? ??, ???? ??, ????? ID ? ??? ?? ?? ???
- Device Files (????)
- ???, ???, ??? ?? ???? ??? ?? ?????? ???? ?? ???
24File ??
- ls -l
- -rw-r--r-- 1 user3 class
44 Mar 26 1621 f1 - -rwxr-xr-x 1 user3 class 67
Mar 26 1622 f2 - drwxrwxrwx 2 user3 class 1024 Mar
26 1612 memo
????
???
??
??
??
Time Stamp
???
Permissions
25?? ?? ???
- ls ?? ?? ??
- cat ?? ?? ??
- more ?? ??? ? ??? ??? ??
- tail ??? ?? ??
- cp ?? ??
- mv ??/???? ?? ??. ?? ??
- rm ?? ??
- diff ???? ??? ???
- ln ??? ????
26cat ???
- ??
- cat file file ??? ??? ???
- ?
- cat f1
- Test file!
- cat f2
- Test file, too!
- cat f1 f2
- Test file!
- Test file, too!
- ??? ?????
- cat gt filename ltEntergt
- This is test file
- ..
- ltCtrlgt d
-
27more ???
- ??
- more filename ??? ??? ??? ??? ???
- ?????
- f, ltCtrlgtf, ltspacegt ?? ? ??? ??? ???
- b, ltCtrlgtb ?? ? ??? ??? ???
- q, Q ?? ??? ???
- v ???? ??? ??
- h help
- ?
- more longfile
- The find command recursively descends the
directory hierarchy for each - path name in pathname_list (that is, one or
more path names) seeking - files that match a Boolean expression
written in the primaries given - below. By default, find does not follow
symbolic links
longfile (5)
28head, tail ???
- ??
- head -n number filename ??? ?? number ?? ???
(default 10) - tail -n number filename ??? ??? number ??
??? (default 10) - tail -f -n number filename -f Follow
Option. - ?
- head -n 10 longfile ( head longfile )
- tail -n 10 longfile ( tail longfile )
- tail -f longfile
- ..
- ltCtrlgt C
-
29cp ???
- ??
- cp -i file1 new_file ??? ?? ???? ???
- cp -i file file dest_dir ??(?)? ??
??????? ??? - cp -r -i dir dir dest_dir ????? ?? ?????
??? ? ? ?? ???? ??? ??? - -i ??? option.
- -r ??? option .
- ?
- ls -F
- f1 f2 memo/ note remind
- cp f1 f1.copy
- ls -F
- f1 f1.copy f2 memo/ note remind
- cp note remind memo
- ls -F memo
- note remind
30mv ???
- ??
- mv -i file1 new_file ??? ??? ??
- mv -i file file dest_dir ??(?)? ?? ????
??? ?? - mv -i dir dir dest_dir ???? ??? ?? ?? ??
???? ? ?? ?? - -i ??? option.
- ?
- ls -F
- f1 f2 memo/ note remind
- mv f1 file1
- ls -F
- file1 f2 memo/ note remind
- mv f2 memo/file2
- ls -F
- file1 memo/ note remind
- ls -F memo
- file2
31rm ???
- ??
- rm -if filename filename .. ??? ???
- rm -r -if filename filename .. ????? ???
- ?
- ls -F
- f1 f2 fruits/ memo/
- rm f1 ls -F
- f2 fruits/ memo/
- rm -i f2
- f2 ? (y/n) y
- rm fruits
- rm fruits directory
- rm -r fruits
32diff ???
- ??
- diff -i file1 file2 ??? ??? ???
- -i ????? ???
- ?
cat fruit1 I like fruits apple orange
cat fruit2 I like fruits apple orange grapes mel
on
cat fruit3 I like fruits very
much apple strawberry
diff fruit1 fruit3 1c1 lt I like fruits --- gt I
like fruits very much 3c3 lt orange --- gt
strawberry
diff fruit1 fruit2 3a4,5 gt grapes gt melon
33ln ???
- ??
- ln file new_file Link to a file
- ln file file dest_dir Link files to a
directory - ?
- ls -l f1
- -rw-r--r-- 1 user3 class 44 Mar
26 1621 f1 - ln f1 /home/user2/f1.link
- ls -l f1
- -rw-r--r-- 2 user3 class 44 Mar
26 1621 f1 - ls -l /home/user2
- -rw-r--r-- 2 user3 class 44 Mar
26 1621 f1.link - ls -i f1 /home/user2/f1.link
- 97852 /home/user2/f1.link 97852 f1
34ln ??? (Hard Link)
- ??
- ln file new_file Link to a file
- ln file file dest_dir Link files to a
directory - ?
- ls -l f1
- -rw-r--r-- 1 user3 class 44 Mar
26 1621 f1 - ln f1 /home/user2/f1.link
- ls -l f1
- -rw-r--r-- 2 user3 class 44 Mar
26 1621 f1 - ls -l /home/user2
- -rw-r--r-- 2 user3 class 44 Mar
26 1621 f1.link - ls -i f1 /home/user2/f1.link
- 97852 /home/user2/f1.link 97852 f1
35?? ??? ??
- UNIX ???? ?? Access ??
- user(???) ??? ???
- group(??) ??? ????? ?? ??
- other(??) ????? ?? ?? ???
- Access ?? read, write, execute
36?? ??? ?? (?)
- ls -l
- - rw- r-- r-- 1 user3 class 32
Mar 26 2208 f1 - - rwxr-x r-x 1 user3 class 52
Mar 26 2209 f2 - drwxr-x r-x 2 user3 class 1024
Mar 26 2107 memo
???
??
??
37??? ?? ?? ???
- chmod ?? ?? ?? ??
- umask ?? ?? ?? ?? ??
- chown ??? ??? ??
- chgrp ??? ?? ??
- su user identifier ??
- newgrp group identifier ??
38chmod
- ??
- chmod mode_list filename ... ??? ?? ?? ??
- mode_list who operator permission ,
- who user, group, other, or all
- operator (add), -(subtract), (set equal to)
- permission read, write,execute
- chmod numeric_mode filename ??? ?? ?? ??
- numeric_mode ??????? ????
- ??
- Orginal Permission mode user group other
- rw-r--r-- rw- r-- r--
- New Permission rwxr-xr-x rwx r-x r-x
- chmod ux, gx, ox file or chmod x
file or chmod 755 file
39umask - ?? ?? ?? ???? ??
- ??
- umask ?? ???? ?? ??? ? ??
- umask mode ???? ?? ??? ? ??
-
- ??
- user group other
- default permissions r w - r w - r w -
- set default permissions r w - r - - - - -
- umask g-w,o-rw
- umask 026
40chown, chgrp
- ??
- chown -R owner filename ?? ???? ??
- chown -R ownergroup filename ???? ??? ?? ??
- chgrp -R group filename ?? ??
- ??
- ls -l f1
- -rw-r--r-- 1 user3 class 32 Mar
26 2208 f1 - -rwxr-xr-x 1 user3 class 52 Mar
26 2209 f2 - chgrp users f1
- ls -l f1
- -rw-r--r-- 1 user3 users 32 Mar
26 2208 f1 - chown user2 f1
- ls -l f1
- -rw-r--r-- 1 user2 users 32 Mar
26 2208 f1 - chown user3users f2
- ls -l f2
- -rwxr-xr-x 1 user3 users 52 Mar
26 2209 f2
41su - Switch User ID
- ??
- su user_name user ID ? group ID ? ??
- su ???? root ? ??
- ??
- id
- uid603(user3) gid600(class)
- su user2
- Password
- id
- uid602(user2) gid600(class)
- ...
- exit or ltCtrldgt
- id
- uid603(user3) gid600(class)
42Remote ??? Access ?? ??
- rlogin ?? Login
- telnet ?? ??
- ftp ????????? ??? ?? ??
43telnet
- ??
- telnet hostname hostname ?? ??????.
- telnet ip_address ip_address? ??????.
- ??
- telnet alpha2 or telnet 105.20.19.210
- Trying...
- Connected to alpha2.
- Escape character is ''.
- Local flow control on
- Telnet TERMINAL-SPEED option ON
-
- HP-UX alpha2 B.10.20 C 9000/887 (ttyp4)
-
- login yuhwa
- Password
- alpha2/user3/yuhwa
44rlogin
- ??
- rlogin hostname -l username hostname ??
??????. - -l username ?? username?? ??????. default ?
????? id - ??
- rlogin alpha2 -l yuhwa or rlogin
150.20.19.210 -l yuhwa - Password
- alpha2/user3/yuhwa
-
45ftp - file transfer program
- ??
- ftp hostname (hostname ??) ???? ????
- ftp ??
- ftpgt ! command ??????? command ??
- ftpgt bye ?? ??? ?? ftp ??
- ftpgt open hostname hostname ??? ???? ??? ??
- ftpgt close ??? ??? ??
- ftpgt get remotefile localfile ??????
remotefile? localfile??? ???? ??(???? ?? ????
??). mgetgt multi-file get - ftpgt put localfile remotefile ?????? localfile
? ?????? remotefile ??? ???? ??gt multi-file put - ftpgt bin Binary ??? ??? ??
- ftpgt asc ASCII ??? ??? ??
- ftpgt prompt Interactive ?? ??
- ftpgt help command (command? ??) help
-
463. vi ??? ??
47vi ??
- ??? ?? ??? (full screen editor)
- - UNIX ??? ??? ???? ?? ?? ???
- - ??? ???? ??? ? ??? ?? ??? ?? ????
- - ??? ??? ???? ?? ??? ??? ? ??
- - ?? ???? UNIX ????? ??
- ??? ???? ????
- - ????? ???? ?????? ???? ??? ?? ???.
- - ???? ?? ???? ?? ??? ??? ???? ??
- export TERMansi
- resize
- - vi ? ????? ??? ?? ??? ?? ltCtrlgtq
- - vi ??? ??? ??? ?? ltCtrlgt l
- - vi ? ??? ?? ??
- vi -r filename
48vi ????
- ??
- vi filename ???? ?? ??? ??? ???
- vi -R filename (cf. view) ??? Read Only ??? ??
- vi -r filename ??? ?? ?? ??
- ?
- vi sample_file
49vi modes
- Command Mode keystrokes ? command ? ??
- Input Mode keystrokes ? ??? ???
- Last Line Mode ex command? ??
/ ?
a i o A I O
Command Mode
Last Line Mode (ex)
return
esc
50vi Session
This is Sample Text file.
?? ??
????
?? ??? ?? ?? ???(?????? ??)
ex commands mode message
or vi ??? ???
51vi ???
- vi ???
- ltescgt ZZ ??? ???? ?? (???? ????)
- ltescgt wq ltReturngt ??? ???? ??
- ltescgt q! ltReturngt ??? ???? ?? ??
- ltescgt q ltReturngt ??? ???? ?? ??
Memory
trash can
sample_file
Disk
ltescgt q! ltReturngt
ltescgt wq ltReturngt
sample_file
52Command Mode - Cursor Control
- ???/?? ??? ??
- - ???(?, ? , ?, ?,)
- - h, backspace(?), j (?), k (?), l (?)
- ?? ??? ??
- - w ???? ?? ??, W space ? ??? ??
- - b ???? ?? ??, B space ? ??? ??
- - e ?? ??? ??? ??
- ? ??? ??
- - , 0 ?? ?? ???? ??
- - ?? ?? ??? ??
- - G ??? ??
- - return ????? ??? ?? ???? ??
53Command Mode - Cursor Control
- ????? ??
- - ctrlb ??? ?? ??,
- - ctrlf ??? ??? ??
- - ctrlu ??? ?? ??
- - ctrld ??? ??? ??
- - H ? ??? ?? ??? ??
- - M ? ??? ???? ??
- - L ? ??? ??? ?? ??
- ?? ???
- ctrll ??? ?? ???.
- ctrlq vi ? ????? ??? ?? ??? ??
54Command Mode - ??/??/??
- ??
- - u ??? ?? ??? ??
- - U ??? ????? ???? ???? ??? ?? ??
- ??
- - x ?? ??? ??? ?? ??
- - dw ??? ??
- - dd ???? ?? ??
- - d ??? ?? ???? ?? ??? ??
- - dG ?? ???? ??? ????? ?? ??
- ??
- - r ?? ??? ??? ??? ??
- - cw ?? ?? ??
- - cc ??? ?? ??
- - cG ??? ?? ???? ?? ??? ??
- - R ltescgt ? ?? ??? ?? ??? ??
55Command Mode - Copy Paste
- ??
- - yw ?? ?? ??
- - yy ??? ??
- - yG ?????? ??? ??? ??? ??
- - y ?? ??? ??
- ???
- - p ????? ??? ?? ?? ??? ??
- - p ????? ??? ?? ?? ??? ??
- ??
- - . ?? ?? ??
- - J ??? ???.
- - ctrlG ???? (????, ?????, ?????, ??) ??
- - ???? ??
56Input Mode ???
- Insert
- - i ?? ?? ????? ??
- - I ?? ??? ?? ?? ???? ??
- Append
- - a ?? ?? ?? ????? ??
- - A ?? ??? ?? ?? ????? ??
- Open
- - o ?? ??? ?? ????? ??
- - O ?? ??? ?? ???? ??
57?? ??? ??
- ?? ???
- /text ??? ?? ???? ??? ????? ??? ??
- ?text ??? ?? ???? ??? ?? ???? ??? ??
- n ??? ?? ??? ?? ??? ?? ???? ??
- N ??? ?? ??? ?? ??? ?? ???? ??
- ??? ?? (???. Regular Expression)
- oOld_text old_text , Old_text
- text ?? ??? ??? text
- text ?? ?? ??? text
- . ????? ??? ??
- character 0? ??? ?? ??
-
58ex ??? - ?? ??? ??
- m,ns/old_pattern/new_pattern/option
- m, n ??? ??? ??? ?? ??. ?? ???? ??? ?? ??? ??
??? ??? ?? - s ?? ???(substitute)
- old_pattern ??? ???(Regular Expression)
- new_pattern ?? ???
- option g - ?? ??? ?? ??
- c - ??? ????? ???
- ???? ???? ?? ?? ??? ???? ??
59ex ???
- w ????? ???? ??
- m,nw file m?? ??? n?? ??? file? ??
- w file ????? ????? file ? ??
- w! file ??? ??? ?? (??? ?? ?)
- e file file ? ???? ?? ??? ??
- e! ????? ????? ???? ?? ??
- e ?? ??? ????? ??
- r file file ? ??? ?? ????? ????
- ! command shell command ? ??
- set option vi ??? ???
- set nooption vi ????? ???
- set all vi ?? ?? option? ?? ???
604. Shell I
61Shell ??
- Shell ???
- - ???? login ? ???? ?, ??? ??? ?? ??loop ????
- Shell ? ??
- - ??? ?????? ??? ?????.
- - ??? ???? ???? ????.
- - ??? ???? ??? ?? child process? ???? ?? ????
???? ??? ?? ?? ?? ???? ????.
whlie (True) printf (prompt ) gets
(str) execvp (str, NULL)
62Shell ??
Users
Shell
environment settings
command execution
Kernel
environment settings
pipelines
Hardware
variable assignment
I/O redirection
variable substitution
filename generation
command substitution
63Shell ??
64Korn Shell ??
- Command Alias
- File name completion
- Command History
- Re-entering command
- Recalling command
- Command line editing
65Aliasing
- ??
- alias ?? ??? ?? alias ? ??
- alias name name ? ??? alias ??
- alias namestring string ? name ?? ??? alias ? ??
- ??
- alias dir'ls -F'
- dir
- f1 f2 f3 memo/ test/
- alias dir
- dirls -F
- alias copycp
- alias del'rm -i'
-
66File Name Completion
- ls -l
- -rw-r--r-- 1 user3 class 32 Mar
26 2208 f1 - -rwxr-xr-x 1 user3 class 52 Mar
26 2209 f2 - -rw-rw-rw- 1 user3 class 32 Mar
27 1947 f3 - -rw-rw-rw- 1 user3 class 23 Mar
27 2205 sample.txt - cat sa ltescgt ltescgt
- cat sample.txt ltReturngt
- ...
- cat f ltescgt ltescgt
- cat f ltescgt
- 1) f1
- 2) f2
- 3) f3
- cat f ltagt1
- ...
-
67Command History Re-entering
- ??
- history -n ??? ?? n ?? ??? ??. ??? 16?
- history a z a???? z????? ??? ??
- r c c?? ??? ???? ?? ?? ??? ??? ? ?? ??? ???
???? - ??
- history -2
- 172 cat sample.txt
- 173 cat f1
- r 173
- cat f1
- ...
- r c
- cat f1
- ...
68Recalling Command Line Editing
- Recalling Commands
- Prompt ?? ltescgt ? ???
- gt ?? vi ??? ???
- vi ???? ???? ??? ???? ????? ?????.
- k ???? ?? ???? ??
- j ???? ?? ???? ??
- nG n?? ???? ??
- ltentergt ? ??? ?? ???? ????.
- Command Line Editing
- ltescgt ? ??? command ??? ????.
- vi command ? ???? line ? ????.
- ltentergt ? ??? ??? ???? ????.
-
69??? ??
- ????
- HOME ? ????? ?? ?? ??
- PATH ??? ???? ?? ??
- TERM, COLUMN, LINES ???? ??? ??
- LOGNAME ?????? ??? ??? ??
- HISTFILE ?? ??? ??
- EDITOR Command Line Editor ??
- ?? ??
- env
- PATH/usr/bin/usr/contrib/bin/
- COLUMNS80
- EDITORvi
- LOGNAMEuser3
- HOME/home/user3
- TERMansi
- LINES29
70??? ?? ??
- Shell ?? ?? ??
- ??
- namevalue ??? ???? ??? ?
- ?
- TERMansi
- ?? ?? ??
- PATH ?? ??? ???? ?? ?? ???? ??
- PATH/usr/bin/usr/contrib/bin/usr/local/bin
- TERM ???? ??? ??
- TERMvt100
- PS1 Shell Prompt String ??
- PS1PWD !
- PS1hostname'PWD'
-
71login ??
- displays the contents of /etc/issue
- issues the login prompt
- runs login
getty
kernel
- validates user name and password
- places user in home directory
- runs the users shell
login
- executes /etc/profile
- executes .profile
- issues the shell prompt
/usr/bin/ksh
72login ??
- displays the contents of /etc/issue
- issues the login prompt
- runs login
getty
kernel
- validates user name and password
- places user in home directory
- runs the users shell
login
- executes /etc/profile
- executes .profile
- issues the shell prompt
/usr/bin/ksh
73Shell ??? ??
- ???? (local variable)
- ?? ??? ??? ???
- ?? ??? ????? ?? ?? ????? ?? ???? ??
- export ???? ??? ?? ??? ???? ??? ? ??
- ???? (environment variable)
- ?? ??? ??? ??
- ?? ????? ?? ??? ? ??
-
74Display Variable Values
- echo HOME
- /home/user3
- env
- PATH/usr/bin/usr/contrib/bin/usr/local/bin/hom
e/user3. - HOME/home/user3
- TERMansi
- set
- PATH/usr/bin/usr/contrib/bin/usr/local/bin/hom
e/user3. - HOME/home/user3
- TERMansi
- dir_namememo/fruits
- file1this
- file2that
- my_lsls -aFC
75Variable Substitution
- ??
- name ?? ??? ??? ??? ???
- ?
- echo PATH
- /usr/bin/usr/contrib/bin/usr/local/bin
- PATHPATHHOME. echo PATH
- /usr/bin/usr/contrib/bin/usr/local/bin/home/use
r3. - dir_namememo/fruits echo dir_name
- memo/fruits
- ls -F dir_name
- apple orange test/
- my_ls"ls -aFC"
- my_ls dir_name
- ./ ../ apple orange test/
76Command Substitution
- ??
- (command) ??? ???? ??? ??
- command
- ?
- pwd
- /home/user3
- curdir(pwd)
- echo curdir
- /home/user3
- cd /tmp
- pwd
- /tmp
- cd curdir
- pwd
- /home/user3
77Tilde Substitution
- ??? ??()? ???? ?? ??? ???
- ?
- ?? / HOME ??? ????? ??
- userid ?? userid ? ? ????
- PWD ??? ??
- - OLDPWD ??? ??
78File Name Generation
- File Name Generating Characters
- ? ??? ?? ??? ?? (?? ?? . ??)
- ?? ??? ???? ???? ??? ??
- - ?????? ?? ??? ??
- ! ?? ???? negate
- 0? ??? ??? ?? (?? ?? . ??)
- ?
- ls -a
- . .. .zz 1G 2G 7G 15G Ant Cat Dog
abc abcdef cyz - echo abc?? gt echo abc cyz
- echo 1-9A-Z gt echo 1G 2G 7G
- echo !A-Z?? gt echo 15G abc cyz
79Quoting
- ??? ??? Shell ??? ??? ??? ???? ?
- Quoting Character
- backslash (\) ?? ??? ??? ??? ???
- single quotes () ?? ???? ?? ?? ????? ??? ???
? ?? - double quotes () ? ???? ?? ????? ???? ???.
- ?? \, , ????, (???)
- Shell ??? ?? ??
- White space ???
- ??
- ????
805. Shell II
- I/O Redirection
- Filter
- Pipe
81stdin, stdout, stderr
File
Device
stdin
stdout
stderr
82Redirection
- ?? ???? ??? ??? ??? overwrite ?
- C Shell ??? ????? gt ?. cp gt cp.err
83Filter
- ??
- ???????? ??? ?? ?????? ??? ????
- ???? ??? ???? ?? ??? ???? ???.
- ?? ???? ???? ??? ???? ? ??.
- ?
- wc Word Count
- sort Alphabetical or Numerical Sort
- grep Pattern Matching
84wc
- ??
- wc -lwc file ???? ?, ??, ???? ??.
- -l ???
- -w ???
- -c ???
- ?
- cat f3
- This is Sample file
- wc f3
- 1 4 20 f3
- wc -l f3
- 1 f3
85sort
- ??
- sort -ndutx -k field_no file ??? line
? sort - -n ??? sort
- -u ???? sort. ???? ?? ??
- -tcharacter ?? ??? character ??. default? ?? ??
? - -k field_no ?????? ?? ?? ?? (default ? ?? line)
- -r Reverse order ? ??
- -M ??? ???? ??
- ?
- tail -1 /etc/passwd
- user3p88gQZpB3S/Fg603600,,,/home/user3/usr/b
in/ksh - 1 2 3 4 5 6 7
- sort -nt -k 3 /etc/passwd
86grep
- ??
- grep -cinv patterns file file ?? patterns
? ???. - grep -cinv -f pattern_file file
- -c ???? ??? ?? ????.
- -i ???? ??? ????? ???? ???.
- -v ??? ???? ?? ?? ??
- -n ??? ? ?? ? ??? ??
- -f ??? ??? ?? ??
- -e ??? 2? ??? ?? ??
- ?
- grep user /etc/passwd
- user2N8aQNxXWCNcJg602600,,,/home/user2/usr/b
in/ksh - user3p88gQZpB3S/Fg603600,,,/home/user3/usr/b
in/ksh - grep -v user /etc/passwd
- grep -i user /etc/passwd
- grep user /etc/passwd
87????? (Regular Expression)
- Regular Expression ??? ???? ??? ???? ?? ?? ???
???? ???? ?? ?? (pattern description)
88pipe
- ???(pipe) ???? ??? ?? ?? ??? ???? ??
- ??
- commandA commandB (pipe) ??? ?? ??? ?????
???? ?? ??? ?????? ??? -
89pipe
stdin
stdin
command A
command A
stderr
stdout
stderr
stdout
stderr
stdout
?? ps -ef more ls more ls sort -r
more command B ? filter ??? ?.
90pipe redirection
stdin
stdin
stdin
command A
command A
command B
stderr
stdout
stderr
stdout
stderr
stdout
?? grep user /etc/passwd sort gt
sorted.users grep user lt /etc/passwd 2gt grep
.err sort gt sorted.users 2gt sort.err grep
user lt /etc/passwd sort 2gt sort.err wc -l gt
wc.out 2gt wc.err
91Some Useful Commands
- wc - word, line, and byte or character count
- sort - sort or merge filesgrep
- grep - search a file for a pattern
- cut - cut out (extract) selected fields of each
line of a file - tr - translate characters
- find - find files
- xargs - construct argument list(s) and execute
command - sed - stream text editor
- awk - pattern-directed scanning and processing
language
92cut
- ??
- cut -c list file ?? ?? stdin ?? ???
- cut -f list -d char -s file ???
character? field ? ??? - option
- -c character ??? ???
- -f field ? ??? ???
- -d -f ??? field ???. default ? tab. ?????
quoting ?? - -s -f ??? ???? ?? line ? ?? (??? ???? ??)
- ?
- date
- Wed Mar 31 105118 JST 1999
- date cut -c 1-3
- Wed
- date cut -d " " -f 1-3
- Wed Mar 31
93tr
- ??
- tr -s string1 string2 stdin?? ???
characters? ???? stdout ?? ?? - tr -d string1 string2
- -s ???? ??? characters ? single character ? ??
- -d character ? ???
- ?
- cat samplefile
- This is sample file.
- cat samplefile tr a-z A-Z
- THIS IS SAMPLE FILE.
- date
- Wed Mar 31 113750 JST 1999
- date tr a-z A-Z
- WED MAR 31 113758 JST 1999
- date cut -d -f 1,2 tr a-z" "A-Z"
- WED MAR
94find - ??
- ??
- find start_dir expressions actions
- start_dir ???? ??. ?? ????? ????? ??
- expressions ???? ??
- -atime n ( or -n) access ??? n days ??(??)? ??
- -mtime n( or -n) modify ??? n days ?? (??)? ??
- -ctime n( or -n) create ??? n days ?? (??)? ??
- -size nc(or -n) ?? ? n byte?? ?(??) ??. c? ???
block?? - -type x ?? type ? x ? ???? ??
- f Regular file d Directory
- b Block special file c Character special
file - p FIFO (named pipe) l
Symbolic link - s Socket
- actions ???? ??? ??? ? ??? ?? ??
- -print ?? ??? ??? ????.
- -ls ?? ??? long format ?? ????.
- -exec ?? ???? exec ?? ??? ??? ????.
- -ok ?? ??? ???? ?? ????? ????.
95find - Example
- ?
- find . -name .profile
- find / -name f1
- find . -name core
- find . -name core -exec rm \
- find / -mtime 7
- find . -mtime -10 -ok rm \
- find / -size 2000
- find / -size -1000000c
- find . -type f -exec chmod 444 \
- find . -type d -exec chmod 555 \
96sed - stream editor
- ??
- sed -n script file ... file(stdin)?? ???
??? script ? ???? ??? stdout ?? ????. - sed -n -e script ... -f script_file ...
file ... - -n stdout ?? ??? ???? ???.
- -e script ? ???? ?? ??
- -f script_file script ? ??? ?? ??
- ?
- sed 's/abc/xyz/' file1 gt file1.out
- sed -e 's/abc/xyz/' -e 's/lmn/rst/' file1gt
file1.out - ls -al sed -n '/....rwxrwx/p gt ls -al
grep .rwxrwx
97awk - Pattern-directed scanning and processing
language
- ??
- awk script filename ??(?)? ???? ?? script ?
???. - awk -f script_file filename ??? script_file
? ?? - ?
- ls -l samplefile
- -rw-rw-rw- 1 user3 class 21 Mar
31 1139 samplefile - ls -al samplefile awk 'print 4, 9'
- class samplefile
- cat data.txt
- 10 20 30 40 50
- 60 70 80 90 100
- awk print 123 data.txt
- 60
- 210
98awk - Pattern-directed scanning and processing
language
- ??
- awk script filename ??(?)? ???? ?? script ?
???. - awk -f script_file filename ??? script_file
? ?? - ?
- ls -l samplefile
- -rw-rw-rw- 1 user3 class 21 Mar
31 1139 samplefile - ls -al samplefile awk 'print 4, 9'
- class samplefile
- cat data.txt
- 10 20 30 40 50
- 60 70 80 90 100
- awk print 123 data.txt
- 60
- 210
99Shell II Lab
100Shell II Lab (??)
1016. Process Control
102ps ???
- ??
- ps -ef ???? ??? ????.
- -e ????? ???? ?? ???? ?? ??
- -f ???? ??? ?? ?? ??
- ?
- ps -ef
- UID PID PPID C STIME TTY TIME
COMMAND - root 0 0 0 Mar 23 ?
019 swapper - root 1 0 0 Mar 23 ?
000 init - user3 3677 3676 0 230116 ttyp1 000
ksh - user3 3714 3677 0 230335 ttyp1
000 grep user3 - user3 3713 3677 5 230335 ttyp1
000 ps -ef
103Background Processing
- ??
- command Background? ??? ????.
-
- ?
- cat while_infinite
- while true do
- echo hello
- done
- while_infinite gt test.out
- 3 18182
- ps -f
- UID PID PPID C STIME TTY TIME
COMMAND - user3 18171 17880 0 220846 pts/3
000 cat - user3 18182 17880 104 221051 pts/3 003
-ksh - user3 17880 14020 0 200221 pts/3
000 -ksh
104Putting Jobs In Background/Foreground
- jobs ?? ???? Job ??
- ltCtrlgtZ ?? Foreground ? ???? ?? Job ? ??
? ?(suspend)?? - fg pid or number ?? ????? Foreground ? ????
- bg pid or number ?? Job Number? Background
? ???? - while_infinite
- 1 18817
- jobs
- 1 Running while_infinite
- fg 18817
- while_infinite
- ltCtrlgt Z
- 1 Stopped while_infinite
- bg
- 1 while_infinite
105nohup ???
- ??
- nohup command ???? logout ? ??? ?? ??? ?
- ?
- nohup while_infinite
- 1 18754
- Sending output to nohup.out
- exit
- logout
- Connection closed.
- login user3
- Password
- ps -ef grep while
- user3 18754 1 169 091940 ? 059 sh
./while_infinite
106kill
- ??
- kill -s signal_name PID PID ??? ??????
???? - kill -s signal_number PID PID ???.
- -s signal_name or signal_number ?????? ???? ??
??? ?? ?? ?? . defaults ? TERM(15) - ?
- while_infinite
- 1 19198
- until_infinite
- 2 19200
- kill 19198 kill -S TERM 19198 kill -1
- 1 - Terminated while_infinite
- kill -s KILL 19200
- 2 Killed until_infinite
- kill -9 0
- Connection closed.
107Process Control Lab
1087. Shell Programming I
109Shell Program
- UNIX ???? ?? ?? Regular ???, UNIX?? ???? ??
?????? ????? ??. - File Permission ? r, x? ???? ??.
- ????
- filename ltReturngt x permission ? ?? ??
- ksh filename ltReturngt x permission ? ?? ??
- ksh -x filename ltReturngt ?????? ? ??? ???? ??
- ???? ?? ??? ????.
- Shell Program ?? ? ? ?? ??
- ?? ??
- ????? ??? ????
- ??? ??? ?? ??
- ?? (?? Check)/ ?? (Branch)/ ?? (Loop)
110??? Shell Program ??
- cat myprog
- this is the program myprog
- date
- ls -F
- chmod x myprog
- myprog
111Shell Program ?? ??? ????
- colorlavender
- cat color1
- echo You are now running program color1
- echo the value of the variable color is color
- ls -l color1
- -rw-rw-rw- 1 user3 class 89 Mar
29 1153 color1 - chmod x color1
- color1
- You are now running program color1
- the value of the variable color is
- export color
- color1
- You are now running program color1
- the value of the variable color is lavender
112Shell Program? Argument
- Command Line
- sh_program arg1 arg2 argN
- 0 1 2 N
- ?
- cat color3
- echo You are now running program 0
- echo The value of command line argument \1 is
1 - echo The value of command line argument \2 is
2 - chmod x color3
- color3 red green
- You are now running program color3
- The value of command line argument 1 is red
- The value of command line argument 2 is green
113Shell Program? Argument (Sample)
- cat my_install
- echo 0 will install 1 to your bin directory
- chmod x 1
- mv 1 HOME/bin
- echo Installation of 1 is complete!
- chmod x my_install
- pwd
- /home/user3
- mkdir bin
- my_install color3
- my_install will install color3 to your bin
directory - Installation of color3 is complete!
- ls -l HOME/bin
- -rwxrwxrwx 1 user3 class 139 Mar
29 1158 color3
114??? Shell Variables
- ?? Shell Variable
- Command Line Arguements? ?
- ?? Command Line Arguments
- ?
- cat color4
- echo There are command line arguments
- echo They are
- echo The first command line argument is 1
- chmod x color4
- color4 red green yellow blue
- There are 4 command line arguments
- They are red green yellow blue
- The first command line argument is red
115??? Shell Variables (Sample)
- cat my_install2
- echo 0 will install files to your bin
directory - echo The files to be installed are
- chmod x
- mv HOME/bin
- echo Installation is complete!
- chmod x my_install2
- my_install2 color1 color4
- my_install2 will install 2 files to your bin
directory - The files to be installed are color1 color4
- Installation is complete!
- ls -l HOME/bin
- -rwxrwxrwx 1 user3 class 89 Mar
29 1153 color1 - -rwxrwxrwx 1 user3 class 101 Mar
29 1221 color4
116Shift ???
- ??
- shift n ??? ??? n ??? ???? ?? (n ??? 1)
- ?
- cat color5
- orig_args
- echo There are command line arguments echo
They are - echo Shifting two arguments shift 2
- echo There are command line arguments echo
They are - color5 red green yellow blue orange
- There are 5 command line arguments
- They are red green yellow blue orange
- Shifting two arguments
- There are 3 command line arguments
- They are yellow blue orange
117Read ???
- ??
- read variable variable ?????? ??? ????
- ?
- cat color6
- echo This program prompts for user input
- echo "Please enter your favorite two colors -gt
\c" - read color_a color_b
- echo The colors you entered are color_a
color_b - color6
- This program prompts for user input
- Please enter your favoriate two colors gt red
blue - The colors you entered are red blue
- color6
- This program prompts for user input
- Please enter your favoriate two colors -gt red
blue white - The colors you entered are red blue white
118Read ??? (Sample)
- cat my_install3
- echo 0 will install files to your bin directory
- echo "Enter the names of the files -gt \c"
- read filenames
- chmod x filenames
- mv filenames HOME/bin
- echo Installation is complete!
- my_install3
- my_install3 will install files to your bin
directory - Enter the names of the files -gt f1 f2
- Installation is complete!
- ls -l HOME/bin
- -rwxr-xr-x 1 user3 class 32 Mar
26 2208 f1 - -rwxr-xr-x 1 user3 class 52 Mar
26 2209 f2
119Shell ?? ???
- ??
- function funct_name shell_script
- or
- funct_name ( ) shell_script
- ?
function install gt gt echo Install file
1 gt chmod x 1 gt mv 1 HOME/bin gt
echo Install complete gt install myfile
install f3 Install file f3 Install complete
install () gt echo Install file 1 gt
chmod x 1 gt mv 1 HOME/bin gt
echo Install complete gt install myfile
install f3 Install file f3 Install complete
or
120Return Code
- shell variable ? holds the return code of the
last command executed - 0 command completed without error (true)
- non-zero command termiated with error (false)
- ?
false echo ? 1 cp Usage cp -f-i -p
-e warnforceignore echo ? 1 echo ? 0
true echo ? 0 ls .. echo ? 0 echo ? 0
121Test ???
- ??
- test expresssion expression ? evaluate ?? return
code ? ??? - expression
- evalutation?? return code
- true 0
- false non-zero (commonly 1)
- Test ???? ??? ??? ??? ? ??.
- Integer
- Strings
- File
122Test ??? - ?? ???
- ??
- number1 relation number2 ???? relation ? ??
??? - relations
- -lt Less than
- -le Less than or equal to
- -gt Greater than
- -ge Greater than or equal to
- -eq Equal to
- -ne Not equal to
- ? (assume X3)
X -gt 7 echo ? 1
X -lt 7 echo ? 0
123Test ??? - ??????
- ??
- string1 string2 ?? ?????? ??
- string1 ! string2 ?? ?????? ??
- string ???? ??? 0 ?? ?
- -z string
- -n string ???? ??? 0? ??? ?
- ?
Xabc X ! abc echo ? 1
Xabc X abc echo ? 0
124Test ??? - ?? ???
- ??
- -option filename ??? ??? ???
- test -option filename
- -f ??? ???? ?? ??(????, ????? ??)?? true
- -s ??? ???? ??? 0?? ?? true
- -r ??? ???? ??? ??? true
- -w ??? ???? ?? ??? true
- -x ??? ???? ???? ??? true
- -d ????? ???? true
- ? ls -l color5
- -rw-rw-rw- 1 user3 class 168 Mar
29 1337 color5 - test -f color5 echo ?
- 0
- test -d color5 echo ?
- 1
125Test ??? - ?? ???
- ??
- -o OR
- -a AND
- ! NOT
- \( \) GROUPING
- ?
- "ANS" y -o "ANS" Y
- "NUM" -gt 10 -a "NUM" -lt 20
- test -s color3 -a -r color3
- test ! -d color3
- \( -eq 2 \) -a \( 1 -eq -n \) -a \(
-d 2 -o -s 2 \)
126If ??
if list A then list B else list
C fi
if list A then list B fi
or
1. list A? ????. 2. ?? ??? ??? list B? ????
???? list C ? ????.
1. list A? ????. 2. ?? ??? ??? list B? ????.
if X -lt 10 then echo X is less than
10 else echo X is not less than 10 fi
if test -s funfile then echo funfile
exists fi
127Case ?? - Multi-direcitonal branching
- ??
- case word in
- pattern1) list A
- pattern2) list B
- patternN) list N
- ) list C
- esac
- ??
word? pattern1? ??? list A? ??, pattern2? ???
list B? ??, , ?? ?? ??? list C ? ????.
case option in 1) echo option 1
2) echo option 2 3) echo option
3 ) echo no option esac
case ANS in yes) echo O.K.
no) echo Not O.K. ) echo Invalid
answser esac
128case ?? - sample
- cat menu_with_case
- echo COMMAND MEMU
- echo d to display time and date
- echo w to display all login user
- echo l to display the contents of current dir
- echo ""
- echo "Please enter your choice \c"
- read choice
- case choice in
- dD) date
- wW) who
- lL) ls
- ) echo Invalide choice
- esac
129Arithmetic Evaluation
- ??
- let expression ???? ???
- (( expression ))
- ?
- x10
- y2
- let xx2
- echo x
- 12
- (( xx/(y2) ))
- echo x
- 3
130while ??
- ??
- while list A
- do
- list B
- done
- ?
??(list A)? ?? ?? list B? ?? ????.
cat test_while X1 while (( X lt 10 )) do
echo X is X let XX1 done test_while X is
1 X is 2 .. X is 10
131until ??
- ??
- until list A
- do
- list B
- done
- ?
??(list A)? ?? ??? list B? ?? ????.
cat test_until X1 while (( X gt 10 )) do
echo X is X let XX1 done test_until X is
1 X is 2 .. X is 10
132for ??
- ??
- for variable in list A
- do
- list B
- done
- ?
variable ? list A? ??? ??? ?????list B ? ????.
cat test_for for X in 1 2 3 4 5 do echo
"2 X is \c" let XX2 echo X done
ksh test_for 2 1 is 2 2 2 is 4 2 3 is 6 2
4 is 8 2 5 is 10
133break, continue, exit ???
- break ??? ??? ????.
- continue ??? ?? ??? ??? ?? ???? ????.
- exit n ?????? ??? ????? n (??? ??? ??? ??
??)? return code ? ????. - ??
cat test_control while true do echo
"Enter file name to remove \c" read
file