1 / 161

UNIX 기초

UNIX 기초. 전민규. 목차. 1. UNIX 시스템 소개 2. 파일 관리 3. vi 편집기 기초 4. Shell I 5. Shell II 6. Process Control 7. Shell Programming I 8. Shell Programming II 9. 시스템 관리 기초. 1. UNIX 시스템 소개. 목 표 1. UNIX 의 특징을 이해한다. 2. Login 과 Logout 을 할 수 있다. 3. UNIX 명령어 형식을 이해한다.

yaholo
Download Presentation

UNIX 기초

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UNIX 기초 전민규

  2. 목차 1. UNIX 시스템 소개 2. 파일 관리 3. vi 편집기 기초 4. Shell I 5. Shell II 6. Process Control 7. Shell Programming I 8. Shell Programming II 9. 시스템 관리 기초

  3. 1. UNIX 시스템 소개 목 표 1. UNIX의 특징을 이해한다. 2. Login 과 Logout을 할 수 있다. 3. UNIX 명령어 형식을 이해한다. 4. 온라인 설명서를 사용할 수 있다. 5. 기본적인 명령어들을 사용할 수 있다.

  4. Disks Memory Users Operating System CPU Programs Network Printers Customers Resources UNIX 소개 운영체제 UNIX 운영체제 시분할 방식의 다중 작업 (Multi-tasking) 다중 사용자 환경 (Multi-user) 높은 이식성과 호환성

  5. UNIX 소개 (계속)

  6. Logging In and Out • login: user1 Login • Password: • Login message • $ date Do work • $ other commands • $ exit or <Ctrl>+d Log out

  7. Command Line 형식 • 형식: • $ command [-option] [argument] • 예: • $ date • Wed Mar 31 20:33:32 JST 1999 • $ ls • dira dirb f1 f2 prog1 prog2 • $ ls -F • dira/ dirb/ f1 f2 prog1* prog2*

  8. Online 매뉴얼 • 형식: • man [-X] command • X: Manual Page Section number • Section 번호와 내용 (HP-UX) • 예 • $ man date • $ man passwd • $ man 4 passwd • 1:User Commands • 1m:System Maintenance Commands (Section 8) • 2:System Calls • 3:Functions and Function Libraries • 4:File Formats • 5:Miscellaneous Topics • 7:Device (Special) Files • 9:Glossary

  9. 기본 명령어 (I) • id 사용자 ID 와 그룹 ID 표시 • $ id • uid=601(user1) gid=600(class) • w 시스템 botting 시간, load, login 사용자 정보(작업)표시 • $ w • 9:00pm up 8 days, 7:31, 4 users, load average: 0.08, 0.03, 0.02 • User tty login@ idle JCPU PCPU what • root console 2:46pm 129:04 -sh • user3 pts/0 2:59pm w • who 현재 login 한 사용자 정보 표시 • root console Mar 24 14:46 • user3 pts/0 Mar 31 14:59 • who am i Local 단말기와 연관된 사용자 정보 표시 • user3 pts/0 Mar 31 14:56

  10. 기본 명령어 (II) • date 시스템 날짜와 시간을 표시 • $ date • Fri Mar 26 14:57:42 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 <Return> • Nice to meet you! <Return> • <Ctrl>+d • mesg 메시지 수신 허용/불가 설정 • $ mesg • is y • $ mesg n • $ mesg • is n • mail mail 사용 • $ mail user1 user1 에게 메일을 보냄 • see you again <Ctrl> + d • $ • $ mail 받은 메일을 읽음

  13. 기본 명령어 (IV) • mail 계속

  14. 2. 파일관리 • File System Hierarchy • File System 기본 명령어 • 파일관련 명령어 • 파일 접근/허가

  15. File System Hierarchy

  16. 절대경로 .vs. 상대경로 (1) • 절대경로 • 파일이나 디렉토리의 이름을 완전하게 지정 • 계층구조의 맨 위(루트)에서 시작 ( / 로 시작) • 현재위치에 상관없음/전체계층구조에서 고유함 • 상대경로 • 계층구조의 현재위치에서 시작 ( / 로 시작하지 않음) • 현재위치에 대해서만 고유 • 특수디렉토리 • 로그인 디렉토리(홈 디렉토리) 시스템 로그인시 들어가는 디렉토리 • Dot (.) 현재 디렉토리 • Dot Dot (..) 현재 디렉토리 바로 위의 상위 디렉토리

  17. 절대경로 .vs. 상대경로 (2)

  18. File System 기본 명령어 • pwd : 작업 디렉토리의 절대경로 표시 • ls : 디렉토리밑의 파일/디렉토리 정보 표시 • cd : 디렉토리 변경 • find : 파일을 찾음 • mkdir : 디렉토리 생성 • rmdir : 디렉토리 삭제

  19. File 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/

  20. File 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

  21. File 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

  22. File 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

  23. File 의 종류 • Regular Files (정규파일) • 1. 텍스트, 데이터, 프로그램 원시 코드 • 2. ls, man, date 등의 실행가능한 프로그램 • Directories (디렉토리) • 담고 있는 파일, 디렉토리 이름, 파일시스템 ID 를 가지고 있는 특수 파일들 • Device Files (장치파일) • 디스크, 단말기, 프린터 등의 하드웨어 장치에 대한 인터페이스를 제공하는 특수 파일들

  24. File 특성 $ ls -l • -rw-r--r-- 1 user3 class 44 Mar 26 16:21 f1 • -rwxr-xr-x 1 user3 class 67 Mar 26 16:22 f2 • drwxrwxrwx 2 user3 class 1024 Mar 26 16:12 memo 파일유형 링크수 그룹 크기 Time Stamp 이름 Permissions 소유자

  25. 파일 관련 명령어 • ls : 파일 정보 표시 • cat : 파일 내용 표시 • more : 파일 내용을 한 스크린 단위로 표시 • tail : 파일의 끝을 표시 • cp : 파일 복사 • mv : 파일/디렉토리 이름 변경. 파일 이동 • rm : 파일 삭제 • diff : 파일들의 차이를 보여줌 • ln : 파일을 링크시킴

  26. cat 명령어 • 형식 • cat file [file …] 파일의 내용을 표시함 • 예 • $ cat f1 • Test file! • $ cat f2 • Test file, too! • $ cat f1 f2 • Test file! • Test file, too! • $ • 간단한 파일만들기 • $ cat > filename <Enter> • This is test file • ….. • <Ctrl> + d • $

  27. more 명령어 • 형식 • more filename한화면 단위로 파일의 내용을 표시함 • 중간명령어 • f, <Ctrl>+f, <space> 다음 한 화면의 내용을 표시함 • b, <Ctrl>+b 이전 한 화면의 내용을 표시함 • 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%)

  28. head, 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 ….. <Ctrl> + C $

  29. cp 명령어 • 형식 • 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

  30. mv 명령어 • 형식 • 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*

  31. rm 명령어 • 형식 • 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

  32. diff 명령어 • 형식 • diff [-i] file1 file2 파일의 내용을 비교함 • -i : 대소문자를 무시함 • 예 $ cat fruit1 I like fruits apple orange $ cat fruit2 I like fruits apple orange grapes melon $ cat fruit3 I like fruits very much apple strawberry $ diff fruit1 fruit3 1c1 < I like fruits --- > I like fruits very much 3c3 < orange --- > strawberry $ diff fruit1 fruit2 3a4,5 > grapes > melon

  33. ln 명령어 • 형식 • 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 16:21 f1 • $ ln f1 /home/user2/f1.link • $ ls -l f1 • -rw-r--r-- 2 user3 class 44 Mar 26 16:21 f1 • $ ls -l /home/user2 • -rw-r--r-- 2 user3 class 44 Mar 26 16:21 f1.link • $ ls -i f1 /home/user2/f1.link • 97852 /home/user2/f1.link 97852 f1

  34. ln 명령어 (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 16:21 f1 • $ ln f1 /home/user2/f1.link • $ ls -l f1 • -rw-r--r-- 2 user3 class 44 Mar 26 16:21 f1 • $ ls -l /home/user2 • -rw-r--r-- 2 user3 class 44 Mar 26 16:21 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 22:08 f1 • - rwxr-x r-x 1 user3 class 52 Mar 26 22:09 f2 • drwxr-x r-x 2 user3 class 1024 Mar 26 21:07 memo 사용자 그룹 기타

  37. 허가와 접근 관련 명령어 • chmod : 파일 접근 권한 변경 • umask : 기본 파일 접근 권한 변경 • chown : 파일의 소유자 변경 • chgrp : 파일의 그룹 변경 • su : user identifier 변경 • newgrp : group identifier 변경

  38. chmod • 형식 • chmod mode_list filename ... 파일의 접근 권한 변경 • mode_list: [who [operator] permission] [, … ] • who user, group, other, orall • 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 u+x, g+x, o+x file or $ chmod +x file or $ chmod 755 file

  39. umask - 파일 모드 작성 마스크값 설정 • 형식 • 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

  40. chown, chgrp • 형식 • chown [-R] owner filename 파일 소유자를 변경 • chown [-R] owner:group filename 소유자와 그룹을 같이 변경 • chgrp [-R] group filename 그룹 변경 • 예제 • $ ls -l f1 • -rw-r--r-- 1 user3 class 32 Mar 26 22:08 f1 • -rwxr-xr-x 1 user3 class 52 Mar 26 22:09 f2 • $ chgrp users f1 • $ ls -l f1 • -rw-r--r-- 1 user3 users 32 Mar 26 22:08 f1 • $ chown user2 f1 • $ ls -l f1 • -rw-r--r-- 1 user2 users 32 Mar 26 22:08 f1 • $ chown user3:users f2 • $ ls -l f2 • -rwxr-xr-x 1 user3 users 52 Mar 26 22:09 f2

  41. su - Switch User ID • 형식 • su user_name user ID 와 group ID 를 바꿈 • su 사용자를 root 로 전환 • 예제 • $ id • uid=603(user3) gid=600(class) • $ su user2 • Password: • $ id • uid=602(user2) gid=600(class) • ... • $ exit or <Ctrl+d> • $ id • uid=603(user3) gid=600(class)

  42. Remote 시스템 Access & 파일 이동 • rlogin: 원격 Login • telnet: 원격 연결 • ftp: 파일전송프로토콜을 이용한 파일 복사

  43. telnet • 형식 • 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]

  44. rlogin • 형식 • 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]

  45. ftp - file transfer program • 형식 • $ ftp [ hostname] (hostname 과의) 파일전송 프로그램 • ftp 명령 • ftp> ! command 지역호스트에서 command 수행 • ftp> bye 현재 연결을 끊고 ftp 종료 • ftp> open hostname hostname 이라는 호스트에 연결을 시도 • ftp> close 현재의 연결을 끊음 • ftp> get remotefile [localfile] 원격호스트의 remotefile을 localfile이라는 이름으로 복사(생략시는 같은 이름으로 복사). mget=> multi-file get • ftp> put localfile [remotefile] 지역호스트의 localfile 을 원격호스트의 remotefile 이라는 이름으로 복사=> multi-file put • ftp> bin Binary 모드로 파일을 복사 • ftp> asc ASCII 모드로 파일을 복사 • ftp> prompt Interactive 모드 제어 • ftp> help [command] (command에 대한) help

  46. 3. vi 편집기 기초 • vi 소개 • 기본 Command

  47. vi ?? • 스크린 단위 편집기 (full screen editor) • - UNIX 시스템 배포시 제공되는 표준 문서 편집기 • - 문자를 입력하고 수정할 수 있도록 하는 대화식 편집 프로그램 • - 새로운 파일을 만들거나 기존 파일을 편집할 때 사용 • - 거의 대부분의 UNIX 시스템에서 사용 • 사용전 알아야할 기본지식 • - 화면전체를 이용하는 편집기이므로 터미널의 특성에 크게 의존함. • - 네트웍을 통해 접속하는 경우 터미널 조정을 해주어야 한다 • $ export TERM=ansi • $ resize • - vi 를 사용하다가 갑자기 키가 멈추는 경우: <Ctrl>+q • - vi 화면이 깨져서 보이는 경우: <Ctrl> + l • - vi 가 갑자기 죽는 경우 • $ vi -r [filename]

  48. Memory sample_file Disk Terminal xxxxxxx xxx…. Display $ vi sample_file sample_file vi 시작하기 • 형식 • $ vi [filename] 기존파일 또는 새로운 파일을 편집함 • $ vi -R filename (cf. view) 파일을 Read Only 상태로 열음 • $ vi -r [filename] 재난을 당한 파일 복구 • 예 • $ vi sample_file

  49. Input Mode vi modes • Command Mode : keystrokes 을 command 로 해석 • Input Mode : keystrokes 시 파일에 입력됨 • Last Line Mode : ex command를 수행 : / ? a i o A I O Last Line Mode (ex) Command Mode return esc

  50. vi Session This is Sample Text file. 파일 내용 문자커서 ~ ~ ~ ~ ~ ~ ~ ~ 화면 표시를 위한 공간 보유자(실제파일에는 없음) :ex commands mode message or vi 편집기 메세지

More Related