1 / 47

제 2 장 유닉스 / 리눅스 사용

제 2 장 유닉스 / 리눅스 사용. 로그인. 실습 서버들 Linux CentOS $ telnet 117.16.244.171 login : s 자기학번 Password: ****** login: stu Password: stu *1* Linux Ubuntu $ telnet 117.16.244.172 login: stu Password: stu *1* Unix Solaris 11 $ telnet 117.16.244.157 login: stu Password: stu *1*.

dulcea
Télécharger la présentation

제 2 장 유닉스 / 리눅스 사용

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. 제2장 유닉스/리눅스 사용

  2. 로그인 • 실습 서버들 • Linux CentOS • $ telnet 117.16.244.171 • login: s자기학번 • Password: ****** • login: stu • Password: stu*1* • Linux Ubuntu • $ telnet 117.16.244.172 • login: stu • Password: stu*1* • UnixSolaris11 • $ telnet 117.16.244.157 • login: stu • Password: stu*1* • 직접 로그인 • X-윈도우 • VMware • 원격 로그인 • telnet • Windows • Unix/Linux • PuTTY • Windows • Unix • Xmanager ( 3장)

  3. 2.1 기본 명령어

  4. 간단한 명령어 사용 $ date $ hostname $ uname $ uname -a $ who $ ls $ clear $ passwd • (Kernel Release Version 의미) • 2. 6. 32- 71. el6. i686 • <Major><Minor><Build><Revision><Version><Architecture> • <Major> 커널에 커다란 변화가 있을 때 바뀌는 번호 • <Minor> 짝수일 때 안정 버전, 홀수일 때 개발버전 • <Build> 패치 레벨을 나타내는 숫자 • <Revision> 패키지개정 횟수를 나타내는 숫자 • <Version> 패키지 버전 (예) el6 : Enterprise Linux (Red Hat Enterprise Linux/CentOS) • <Architecture> 프로세서 (예) i686 : Intel Pentiumprocessor (= x86 microarchitecture)

  5. (실습) 유닉스/리눅스디렉토리 이해 $ ls/usr/bin $ ls /usr/include $ ls /usr/lib $ ls /usr/libexec $ ls /usr/local $ ls/usr/sbin $ ls /usr/share $ ls /usr/src • 리눅스파일시스템의 디렉토리 용도와 파일 개수를 알아보세요 • (참고) • 교재 p41~42 • web • http://proton.pathname.com/fhs/ • $ ls / | wc [-w] • $ ls/bin| wc [-w] • $ df $ ls / $ ls/bin $ ls /boot $ ls /dev $ ls /etc $ ls /home $ ls /kernel (Unix only) $ ls /lib $ ls /lost+found $ ls /media $ ls /mnt $ ls /opt $ ls /proc $ ls /root $ ls/sbin $ ls /tmp $ ls /usr $ ls /var

  6. 리눅스 디렉토리 계층구조 • 리눅스의 디렉터리도 루트로부터 시작하여 계층구조를 이룬다 $ cat/proc/1/maps 또는 $ ps $ cat /proc/PID/maps

  7. 유닉스 디렉토리 계층구조 • 유닉스의 디렉터리는 루트로부터 시작하여 계층구조를 이룬다

  8. Linux 설치: 하드 디스크 분할 • (Linux) • $ getconfPAGESIZE • 4096 • (Solaris) • $ pagesize –a • 4092 • 2097152 • 여러 파티션의 장점 • 부팅시 파일 시스템 체크에 필요한 시간을 줄여줌 • 파일들은 파티션 경계를 넘어서 커질 수 없음 • bad spot 발생시 해당 파티션만 재설치 하면 됨 • 각 파티션별 비율 (파티션 연습 후 재설정하세요!) • swap 가상메모리 영역 일반적으로 메모리의 2배정도 (4096M = 4G) Linux-2.2 이후 512MB 제한 없음, 2*1K-block=2048 이상 성능 영향 없음 $ dumpe2fs /dev/sda1 | grep “Block size” $ tune2fs –l /dev/sda1 | grepBlock $ cat /proc/swaps $ free ******************************************************************************************* • /boot 커널과 부트스트랩과정에 필요한 파일이 들어 있는 곳 PC BIOS의 한계성으로 인해, 이런 파일들이 저장할 소형33 파티션를 잡아주는 것이 좋음 (500M) ……………………………………………………………………………………… • /한 덩어리 약 55% 정도(예, 100G/200G) ……………………………………………………………………………………… • / 최상위 디렉토리로서 약 8% 정도(8G) • /usr일반 사용자 프로그램을 설치할 디렉토리로 약 35%정도 (35G) • /var각종 로그 파일 및 메일에 관련된 곳 약12% 정도(12G) ******************************************************************************************* • /home 사용자들의 홈디렉토리가 위치해 있고 웹서버의 자료가 위치하는 곳 약 45% 정도(나머지)

  9. 2.2 파일 및 디렉터리

  10. 파일의 종류 • 일반파일(ordinary file) “-”$ ls -l • 데이터를가지고있으면서디스크에저장된다. • 디렉터리(directory)/폴더(folder) “d” $ ls -l • 디렉터리(폴더) 자체도 하나의 파일로 다른 디렉터리들을 포함하여 계층 구조를 이룬다 • 부모 디렉터리는 다른 디렉터리들을 서브 디렉터리로 갖는다 • 특수파일(special file) • 장치 파일: 물리적인장치에대한내부적인표현 $ ls –l /dev • 문자 단위 입출력 장치 파일: 키보드(stdin), 모니터(stdout), 프린터등 “c” • 블록 단위 입출력 장치 파일: 하드디스크 등 “b” • 통신파일 • 파이프파일(file) “p” $ mknodmypipe p • 소켓파일(file) “s” $ chef & ; cook /* socket()시스템 호출로 소켓파일 생성 */ • 링크 파일 $ ls –l /bin • 심볼릭(소프트) 링크(symboilic link) 파일 “l” • $ cp –r /socket. • $ cd socket • $ gccchef.c –o chef • $ gcccook.c –o cook • $ ./chef& • $ ./cook

  11. 홈 디렉터리/현재 작업 디렉터리 • 홈 디렉터리(home directory) • 각 사용자마다 별도의 홈 디렉터리가 있음 • 사용자가 로그인하면 홈 디렉터리에서 작업을 시작함 • 현재 작업 디렉터리(current working directory) • 현재 작업 중인 디렉터리 • 로그인 하면 홈 디렉터리에서부터 작업이 시작된다.

  12. 디렉터리 관련 명령 • pwd(print working directory) • 현재 작업 디렉터리를 프린트 • $ pwd • cd(change directory) • 현재 작업 디렉터리를 이동 • $ cd [디렉터리] • mkdir(make directory) • 새 디렉터리를 만듬 • $ mkdir 디렉터리

  13. 디렉터리 리스트 • ls(list) 디렉터리의 내용을 리스트 • $ ls test • $ ls –s -s(size) 총 4 4 test • $ ls –a -a(all) . .. .bash_history test • $ ls–i-i(inode) 4718595 test • 현업에서 정말 많이 사용: ls, grep, find, vi • # dumpe2fs /dev/sda1 | grepsize • # tune2fs –l /dev/sda1 | grepsize

  14. 디렉터리 리스트 • $ ls –l -l(long) 합계 4 -rw-rw-r--. 1 stustu 7 2013-09-11 11:11 test • $ ls –asl 합계 32 4 drwx------. 4 stustu 4096 2013-09-11 12:13 . 4 drwxr-xr-x. 17 root root 4096 2013-09-11 12:12 .. 4 -rw-r--r--. 1 stustu 18 2011-05-31 01:58 .bash_logout 4 -rw-r--r--. 1 stustu 176 2011-05-31 01:58 .bash_profile 4 -rw-r--r--. 1 stustu 124 2011-05-31 01:58 .bashrc 4 drwxr-xr-x. 2 stustu 4096 2010-11-12 09:54 .gnome2 4 drwxr-xr-x. 4 stustu 4096 2012-08-08 08:50 .mozilla 4 -rw-rw-r--. 1 stustu 7 2013-09-11 12:13 test • $ ls –il 4718595 -rw-rw-r--. 1 stu stu 7 2013-09-11 11:11test

  15. 경로명 • 파일이나 디렉터리에 대한 정확한 이름 • 절대 경로명(absolute pathname) • 루트 디렉터리로부터 시작하여 경로 이름을 정확하게 적는 것 • 상대 경로명(relative path name) • 현재 작업 디렉터리부터 시작해서 경로 이름을 적는 것 ~ : 홈 디렉터리 . : 현재 디렉터리 .. : 부모 디렉터리

  16. 파일 내용 리스트 • 파일 내용 출력과 관련된 다음 명령어들 • cat, more, less, head, tail, wc, 등 $ 명령어 파일 $ 명령어 파일* (*는모든 글자) $ more 파일+ (+는모든 파일) $ less 파일+ (+는모든 파일) :[Space] :[Enter] :b

  17. cat 명령어 • 파일내용 출력 $ cat xx $ cat ... ^D $ cat > xx ... ^D $ cat >> xx ... ^D

  18. more/head/tail/wc • more 명령어 하나 이상의 파일 이름을 받을 수 있으며 각 파일의 내용을 페이지 단위로 출력 • head 명령어 파일의 앞부분(10줄)을 출력 • tail 명령어 파일의 뒷부분(10줄)을 출력 • wc(word count) 파일에 저장된 줄, 단어, 문자의 개수를 세서 출력 $ wc test 1 1 7 test

  19. cp 명령어 • $ cp파일1 파일2 파일1의 복사본 파일2를 현재 디렉터리에 만든다 $ cp xx yy $ ls –il 4718602 -rw-rw-r--. 1 stu stu 3 2013-09-11 12:29 xx 4718603 -rw-rw-r--. 1 stu stu 3 2013-09-11 12:29 yy • $ cp파일 디렉터리 파일1의 복사본을 디렉터리 내에 만듬 $ mkdirdd $ cp xx dd $ ls–il 4718604 drwxrwxr-x. 2 stustu 4096 2013-09-11 12:30 dd 4718602 -rw-rw-r--. 1 stustu 3 2013-09-11 12:29 xx 4718603 -rw-rw-r--. 1 stustu 3 2013-09-11 12:29 yy

  20. mv 명령어 • mv(move) 파일1의 이름을 파일2로 변경한다 $ mv파일1 파일2 $ mvyyzz $ ls -il 4718604 drwxrwxr-x. 2 stustu 4096 2013-09-11 12:30 dd 4718602 -rw-rw-r--. 1 stustu 3 2013-09-11 12:29 xx 4718603 -rw-rw-r--. 1 stustu 3 2013-09-11 12:29 zz • 파일을 디렉터리 내로 이동 $ mv파일 디렉터리 $ mv zzdd $ ls -il 4718604 drwxrwxr-x. 2 stu stu 4096 2013-09-11 12:31 dd 4718602 -rw-rw-r--. 1 stu stu 3 2013-09-11 12:29 xx

  21. ln 명령어 • ln(link) 파일1의 이름을 파일2로 링크한다 $ ln파일1 파일2 $ ln xx yyy $ ls –il 4718604 drwxrwxr-x. 2 stustu 4096 2013-09-11 12:31 dd 4718601 -rw-rw-r--. 1 stustu 7 2013-09-11 12:13 test 4718602 -rw-rw-r--. 2 stustu 3 2013-09-11 12:29 xx 4718602 -rw-rw-r--. 2 stustu 3 2013-09-11 12:29 yy • 심볼릭 링크 $ ln –s 파일1 파일2 $ ln –s xx zzz $ ls -il 4718604 drwxrwxr-x. 2 stustu 4096 2013-09-11 12:31 dd 4718601 -rw-rw-r--. 1 stustu 7 2013-09-11 12:13 test 4718602 -rw-rw-r--. 2 stustu 3 2013-09-11 12:29 xx 4718602 -rw-rw-r--. 2 stustu 3 2013-09-11 12:29 yy 4718606 lrwxrwxrwx. 1 stustu 2 2013-09-11 12:33 zz -> xx

  22. 파일/디렉토리 삭제 • rm(remove) 명령어 명령줄 인수로 받은 파일(들)을 지운다 $ rm파일+ $ rm xx • $ rm -r 디렉터리 ( 조심해서사용) 디렉터리 내의 모든 파일 및 하위 디렉터리들을 단번에 지운다 $ rm -r dd • rmdir(remove directory) 명령어 명령줄 인수로 받은 디렉터리(들)을 지운다 $ rmdir디렉터리+ 주의: 디렉터리 내에 아무 것도 없어야 한다 $ rmdirdd

  23. 2.3 파일 속성

  24. 파일 속성(file attribute) • 파일의 이름, 타입, 크기, 소유자, 사용권한, 수정 시간 $ ls -sl xx 6 -rw-r--r--. 1 stustu 7 2013-09-1111:11 test

  25. 사용권한(permission mode) • 읽기(r), 쓰기(w), 실행(x) 권한 • 파일의 사용권한은 소유자(owner)/그룹(group)/기타(others)로 구분하여 관리한다 x • 소유자 그룹 기타 rw- rw- rw— (text file default) 000 010 010 (umask) • rw- r-- r-—

  26. X 윈도우의 GNOME 데스크톱에서 속성 확인 기본 속성 사용권한

  27. chmod(change mode) • 사용권한 - rw- rw- r-- • 2진수: 110 100 100 • 8진수: 6 4 4 • $ umask • $ umask 002 • $ cat > xx • $ umask • $ chmod777 xx • $ chmod 000 xx • $ cat xx • [u|g|o|a]+[+|-|=][r|w|x]+ • u(user), g(group), o(other), a(all) • 연산자: +(추가), -(제거), =(지정) • 권한: r(읽기), w(쓰기), x(실행) • $ chmoda+r xx • $ cat >> xx • $ chmodu+w xx • (# mkdir /dd) • $ cat >> /dd/SMY • $ chmod 777 dd • $ chmod 1777 dd • 파일 혹은 디렉터리의 사용권한을 변경하는 명령어 • $ chmod [-R] 사용권한 파일 /* -R : Recursive */ • -R 옵션은 디렉터리 내의 모든 파일, 하위 디렉터리에 적용 • 디렉터리 sticky bit • $ chmod1777 dd

  28. (참고) set-user-id set-group-id set-sticky bit • Symbolic File Access Modes $ chmod a=rw xx $ chmodg+x xx $ chmod g-rwx xx $ chmod g=u xx • Octal File Access Modes $ chmod 644 xx $ chmod 751 xx $ chmod 000 xx • 실행파일에 대하여 • 4000 set user ID : $ chmod 4751 xx • $ chmodu+s xx • 2000 set group ID : $ chmod 2751 xx • $ chmodg+s xx • 1000 set sticky bit : $ chmod 1751 xx • $ chmodo+t xx $ find / -perm -4755 -ls > result $ find / -perm 4700 -ls > result • 디렉토리에 대하여 • 1000 set sticky bit : $ chmod 1777 share • 그 디렉토리 안의 파일제거 또는 이름 변경은 파일 소유자, 디렉토리 소유자, 수퍼유저만 가능 • 다른 사용자는 그 안에 자기파일 생성만 • umask (user mask) : file 생성시 허가권 제한 - rws r-x --x - 100 111 101 001 - rwx r-s --x - 010 111 101 001 - rwx r-x --t - 001 111 101 001

  29. [#] chown(change owner)/chgrp(change group) [#] rootprompt • chown명령어 파일이나 디렉터리의 소유자를 변경할 때 사용한다 $ chown사용자 파일 $ chown [-R] 사용자 디렉터리 • chgrp명령어 파일의 그룹을 변경할 수 있다 $ chgrp그룹 파일 $ chgrp [-R] 그룹 디렉터리 • 파일의 소유자 또는 슈퍼 유저만 사용 가능 !

  30. 2.4 입출력 재지정 및 파이프

  31. 출력 재지정(output redirection) • 명령어의 표준출력 내용을 모니터에 출력하는 대신에 파일에 저장 $ 명령어 > 파일 $ who > names

  32. 출력 재지정 예 • $ cat > xx Hi ! This is the first list. ^D • $ cat > yy Hello ! This is the second list. ^D • $ cat xx yy > zz • $ cat zz Hi ! This is the first list. Hello ! This is the second list.

  33. 출력 추가 • 명령어의 표준출력을 모니터 대신에 기존 파일에 추가 $ 명령어 >> 파일 $ cat >> list1 Bye ! This is the end of the first list. ^D $ cat list1 Hi ! This is the first list. Bye ! This is the end of the first list.

  34. 입력 재지정(input redirection) • 명령어의 표준입력을 키보드 대신에 파일에서 받는다. $ 명령어 < 파일 $ wc < list1 4 17 71 list1

  35. 문서 내 입력(here document) • 명령어의 표준입력을 단어가 다시 나타날 때까지의 내용으로 • 보통 스크립트 내에서 입력을 줄 때 사용 $ 명령어 << 단어 ... 단어 $ wc << end hello ! word count end 2 420

  36. 파이프 • 로그인 된 사용자들을 정렬해서 보여주기 $ who > names $ sort < names • $ 명령어1 | 명령어2 • 명령어1의 표준출력을 명령어2의 표준입력으로 바로 받는다. $ who | sort

  37. 2.5 후면 처리 및 프로세스

  38. 전면 처리 vs 후면처리 • 전면 처리 (foregroundprocessing) • 명령어를 입력하면 명령어가 전면에서 실행되며 명령어 실행이 끝날 때까지 쉘이 기다려 준다 • $ 명령어 ; 명령어 • 후면 처리 (background processing) • 명령어들을 후면에서 처리하고 전면에서는 다른 작업을 할 수 있으면 동시에 여러 작업을 수행할 수 있다 • $ 명령어 &

  39. 후면 처리 예 (교재 p69) • $ (sleep 1000; echo done1) & [1] 8320 • $ (sleep 1000; echo done2) & [2] 8325 • $ find/ -name xx -print & [2] 8330 • $ jobs [1] Running ( sleep 1000; echo done1 ) [2] - Running ( sleep 1000; echo done2 ) [3] + Running find / -name xx –print • $ fg %작업번호 $ fg %1 ( sleep 100; echo done ) $ Control-Z $ bg %1 • 후면처리 입출력 $ find / -name xx -print > result& $ find / -name xx –print > result 2> err & $ find / -name xx -print > result 2>&1 & $ wc < inputfile &

  40. 프로세스(process) • 실행중인 프로그램을 프로세스(process)라고 부른다 • 각 프로세스는 유일한 프로세스 번호 PID를 갖는다 • ps명령어를 사용하여 나의 프로세스들을 볼 수 있다 $ ps PID TTY TIME CMD 8695 pts/3 00:00:00 csh 8720 pts/3 00:00:00 ps $ ps u (u: user oriented display) USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND mysung 8695 0.0 0.0 5252 1728 pts/3 Ss 11:12 0:00 -csh mysung 8793 0.0 0.0 4252 940 pts/3 R+ 11:15 0:00 ps u

  41. psaux (BSD style) $ ps aux (a: all, u: user-oriented, x: including without tty) USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 2064 652 ? Ss 2011 0:27 init [5] root 2 0.0 0.0 0 0 ? S< 2011 0:01 [migration/0] root 3 0.0 0.0 0 0 ? SN 2011 0:00 [ksoftirqd/0] root 4 0.0 0.0 0 0 ? S< 2011 0:00 [watchdog/0] ... root 8692 0.0 0.1 9980 2772 ? Ss 11:12 0:00 sshd: mysung [pr mysung 8694 0.0 0.0 9980 1564 ? R 11:12 0:00 sshd: mysung@pts mysung 8695 0.0 0.0 5252 1728 pts/3 Ss 11:12 0:00 -csh mysung 8976 0.0 0.0 4252 940 pts/3 R+ 11:24 0:00 ps aux (cf.) $ ps –ef $ ps-af

  42. kill & killall명령어 • 프로세스를 강제적으로 종료시키는 명령어 $ kill 프로세스번호 $ killall프로세스이름 $ kill %후면작업번호 $ kill 8320 혹은 $ kill %1 $ ps [1] Terminated ( sleep 100; echo done ) $ kill [bash PID] $ kill -9 [bash PID]

  43. 2.6 문서편집기

  44. gedit • GNOME이 제공하는 GUI 기반 문서편집기 • 사용방법 • [프로그램] -> [보조 프로그램] -> [gedit텍스트 편집기] • $ gedit [파일이름] & • 기능 • 파일: 새로 만들기, 열기, 저장 닫기 • 편집: 입력취소, 잘라내기, 복사 붙여넣기 • 보기: 도구모음, 상태표시줄, 전체화면 • 검색: 찾기, 바꾸기 • 검사: 맞춤법 검사 • 문서: 모두 저장, 모두 닫기 • 도움말

  45. kwrite • KDE 데스크톱 환경이 제공하는 GUI 기반 문서 편집기 • 기능 • 파일: 새문서, 열기, 저장, • 편집: 실행취소, 잘라내기, 복사 붙여넣기 • 보기: 새창, 줄번호, 글꼴크기 • 도구: 맞춤법 검사, 들여쓰기 대소문자 변환, 정렬 • 설정: 도구모음, 상태표시줄, 편지기 설정, 단축키 설정 • 도움말

  46. 핵심 개념 • 유닉스의 디렉터리는 루트로부터 시작하여 계층구조를 이룬다 • 절대 경로명은 루트 디렉터리부터 시작하고 상대 경로명은 현재 디렉터리부터 시작한다 • 파일의 사용권한은 소유자, 그룹, 기타로 구분하여 관리한다 • 출력 재지정은 표준출력 내용을 파일에 저장하고 입력 재지정은 표준입력을 파일에서 받는다 • 실행중인 프로그램을 프로세스라고 한다 • Linux 기본 명령어  1장 & 2장 퀴즈 • 1장 & 2장 교재와 ppt • (참고) http://www.mireene.com/webimg/linux_tip1.htm

  47. 과제 1 (9/26금 23:59까지 제출) • [과제1] 117.16.244.171 CentOS의 아래 디렉터리들의 용도와 파일 개수를 조사하여 제출합니다 ☞ Chapter 2 수업자료 p5 (1) 루트(/) 디렉터리 아래의 중요 디렉터리(2) /usr디렉터리 아래의 중요 디렉터리$ ls  /$ ls  /bin$ ls  /boot$ ls  /dev$ ls  /etc$ ls  /home$ ls  /kernel (Unix only)$ ls  /lib$ ls  /lost+found$ ls  /media$ ls  /mnt$ ls  /opt$ ls  /proc$ ls  /root$ ls  /sbin$ ls  /tmp$ ls  /usr$ ls  /var$ ls  /usr/bin$ ls  /usr/include$ ls  /usr/lib$ ls  /usr/libexec$ ls  /usr/local$ ls  /usr/sbin$ ls  /usr/share$ ls  /usr/src

More Related