1 / 56

제 5 장 유틸리티

제 5 장 유틸리티. 5.5 vi 에디터. 5.5 vi 먼저 배우고 vi 로 텍스트 파일 you 작성합니다. vi editor (visual editor). 기본 텍스트 에디터로 매우 강력한 기능을 가지고 있으나 배우는데 상당한 시간과 노력이 필요하다 $ vi 파일 *. 명령 모드 / 입력 모드. vi 에디터는 명령 모드와 입력 모드가 구분되어 있으며 시작하면 명령 모드이다 마지막 줄 모드 :wq 작업 내용을 저장하고 종료 (ZZ 와 동일한 기능 )

Télécharger la présentation

제 5 장 유틸리티

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. 제5장 유틸리티

  2. 5.5 vi 에디터 5.5 vi 먼저 배우고 vi로 텍스트파일 you 작성합니다

  3. vieditor(visual editor) • 기본 텍스트 에디터로 매우 강력한 기능을 가지고 있으나 • 배우는데 상당한 시간과 노력이 필요하다 $ vi 파일*

  4. 명령 모드/입력 모드 • vi 에디터는 명령 모드와 입력 모드가 구분되어 있으며 • 시작하면 명령 모드이다 • 마지막 줄 모드 • :wq 작업 내용을 저장하고 종료 (ZZ와 동일한 기능) • :q 아무런 작업을 하지 않은 경우의 종료 • :q! 작업 내용을 저장하지 않고 종료

  5. replace append insert open esc esc esc esc a A i I R oO $vi filename ~ ~ vi mode(vi 명령 모드) ~ $ :q! (기록 않음) ZZ(기록) :wq :x x dd r 커서이동 (실습) $ vi rain H J K L  Unix/Linux

  6. vi 편집: rain (Uriah Heep) http://www.youtube.com/watch?v=AVEqXkTozk8 $ virain It's raining outside but that's not unusual But the way that I'm feeling is becoming usual I guess you could say The clouds are moving away Away from your days And into mine Now it's raining inside and that's kind of a shame And it's getting to me, a happy man And why should you want to Waste all my time The world is yours But I am mine Rain, rain, rain, in my tears Measuring carefully my years Shame, shame, shame, in my mind See what you've done to my life Rain, rain, rain, in my tears Measuring carefully my years Shame, shame, shame, in my mind See what you've done to my life See what you've done to my life

  7. vi 내부 명령어 • 입력모드로 전환하는 명령 • 수정 혹은 삭제 명령 • 원하는 위치로 이동하는 명령 • 복사 및 붙이기 • 기타 :명령

  8. 입력모드로 전환하는 명령 • 입력모드로 전환 i 커서 위치 앞에 삽입 a 커서 위치 뒤에 삽입 I 현재 줄의 앞에 삽입 A 현재 줄의 뒤에 삽입 o 현재 줄의 아래에 전개 O 현재 줄의 위에 전개

  9. 수정 혹은 삭제 명령 • 현재 커서를 중심으로 수정 r 단지 한 글자만 변경 R 입력하는 대로 겹쳐 쓰기 s 현재 글자 삭제 삽입 상태 C 커서로부터 줄 끝까지 변경 cc 현재 줄 전체를 변경 cw현재 단어를 삭제하고 변경 • 삭제 x 커서가 있는 문자 지우기 X 커서의 왼쪽 문자 지우기 D 커서부터 줄 끝까지 지우기 dd현재 줄의 전체를 지우기 :n,m d n~m번째 줄 삭제 • 기타 ~ 대문자는 소문자로 소문자는 대문자로 변경 J 커서가 있는 줄 아래 줄을 커서 줄로 접합

  10. 복사/붙이기 • 줄 내용 복사(copy) yy현재 줄 복사 nY현재 줄에서부터 n개의 줄을 복사 :n,m y n번째 줄에서 m번째 줄까지를 버퍼에 복사함 :1,5y • 마지막으로 삭제/복사한 내용을 붙이기(put) p버퍼 내용을 커서의 뒤(혹은 아래)에 삽입 P 버퍼 내용을 커서의 앞(혹은 위)에 삽입 :2pu

  11. 원하는 위치로 이동하는 명령 • 커서 이동 h, ← 한 칸 왼쪽 j, ↓한 칸 아래쪽 k, ↑ 한 칸 위쪽 l, → 한 칸 오른쪽 BACKSPACE 왼쪽으로 한 칸 SPACE 오른쪽으로 한 칸 - 이전 줄의 처음 + 다음 줄의 처음 RETURN 다음 줄의 처음 0 현재 줄의 맨 앞 $ 현재 줄의 끝 ^ 현재 줄의 첫 글자 W 다음단어의 첫 글자 B 이전단어의 첫 글자 • 화면 이동 ^F 한 화면 아래로 ^B 한 화면 위로 ^D 반 화면 아래로 ^U 반 화면 위로 • 특정 줄로 이동 nG n번째 줄로 이동 1G 첫 줄로 이동하기 G 마지막 줄로 이동하기 :n n번째 줄로 이동 • 탐색(search) /탐색패턴 forward 탐색 ?탐색패턴 backward 탐색

  12. 대치, 수행취소/재수행 • 대치 명령 • 해당되는 줄의 첫 번째 단어만 대치 • :s/패턴/스트링 :s/rain/snow 현재 줄에서 대치 • :n,m s/패턴/스트링 :1,$ s/rain/snow 또는 :% s/rain/snow 지정된 줄 범위에서 대치 • :n s/패턴/스트링 :20 s/rain/snow 지정된 줄(n)에서 대치 • :s/패턴/스트링/g :1,$ s/rain/snow/g 또는 :% s/rain/snow/g 해당되는 모든 단어 대치 • 수행취소/재수행 u 방금 전 수행 내용 취소(Undo) U 현재 줄 수행 내용을 취소 . 방금 전 수행 내용을 반복(Redo)

  13. 기타 :명령 • 다른 파일 편집 :e 파일이름 현재 파일 대신에 주어진 파일 열기 :e! 파일이름 저장 여부를 점검하지 않고 파일 변경 :e# 이전 파일을 다시 열기 • 문법 체크 색상 없애기 :syntax off • 줄 번호 붙이기 줄 번호를 붙이거나 없애기 :set number 줄번호 붙이기 :se nu 줄번호 붙이기 :set nonumber줄번호 없애기 :se nonu줄번호 없애기 • 쉘 명령어 수행(쉘 나들이) • 편집기 내에서 쉘 명령어 수행 :!ls :!pwd :!sh … exit 또는 ^D

  14. HW 제출을 위한 ftp (Linux  Windows) ftp> binary 200 Switching to Binary mode. ftp> ls 200 PORT command successful. Consider using PASV. 150 Here comes the directory listing. REMOTEHOST=10.80.77.247 REMOTEHOST=117.16.244.61 rain you 226 Directory send OK. • ftp: 109 bytes received in 0.00Seconds 109000.00Kbytes/sec. • ftp> get rain • 200 PORT command successful. Consider using PASV. • 150 Opening BINARY mode data connection for mycp.c (849 bytes). • 226 Transfer complete. • ftp: 849 bytes received in 0.00Seconds 849000.00Kbytes/sec. • ftp> bye • 221 Goodbye. • D:\> • 시스템 등록 정보고급환경 변수새로 만들기 PATH=C:\WINDOWS\system32 • 윈도우즈 명령 프롬프트에서 C:\>D: [Enter] D:\>ftp 117.16.244.171 Connected to 117.16.244.59. 220 (vsFTPd 2.3.4) User (117.16.244.171:(none)): 자기아이디 331 Please specify the password. Password: 230 Login successful.

  15. 5.1 파일 관련 유틸리티

  16. vi 편집: you http://www.youtube.com/watch?v=9bxc9hbwkkw When I am down and, oh my soul, so weary When troubles come and my heart burdened be Then, I am still and wait here in the silence Until you come and sit awhile with me You raise me up, so I can stand on mountains You raise me up, to walk on stormy seas I am strong, when I am on your shoulders You raise me up, to more than I can be There is no life - no life without its hunger; Each restless heart beats so imperfectly; But when you come and I am filled with wonder, Sometimes, I think I glimpse eternity

  17. 필터링: grep 명령어 • $ grep패턴 파일* • 대상 파일들을 읽어서, 해당 패턴을 검색하고, 패턴을 포함하는 줄을 출력 • $ grep with you Until you come and sit awhile with me There is no life - no life without its hunger; But when you come and I am filled with wonder, • $ grep -w with you Until you come and sit awhile with me But when you come and I am filled with wonder, • $ grep -n with you 4:Until you come and sit awhile with me 15:There is no life - no life without its hunger; 17:But when you come and I am filled with wonder,

  18. grep 명령어 • $ grep -i when you When I am down and, oh my soul, so weary When troubles come and my heart burdened be I am strong, when I am on your shoulders But when you come and I am filled with wonder, • $ grep -v raise you (v: invert) When I am down and, oh my soul, so weary When troubles come and my heart burdened be Then, I am still and wait here in the silence Until you come and sit awhile with me I am strong, when I am on your shoulders There is no life - no life without its hunger; Each restless heart beats so imperfectly; But when you come and I am filled with wonder, Sometimes, I think I glimpse eternity

  19. 정규표현식(regular expression) • 정규표현식을 이용한 패턴 기술 • . : 임의의 한 문자 • * : 0개 이상 예)a*b는 b, ab, aab, aaab, ... • [ ] : [과 ] 사이의 문자 중 하나 • ^, $ : 각각 줄의 시작과 끝을 의미한다. • $ grep -w ‘st.*’ you Then, I am stilland wait here in the silence You raise me up, so I can standon mountains You raise me up, to walk on stormyseas I am strong, when I am on your shoulders • $ grep ‘[X-Z]’ you You raise me up, so I can stand on mountains You raise me up, to walk on stormy seas You raise me up, to more than I can be

  20. 정렬: sort 명령어 • sort 명령어 • 텍스트 파일을 정렬 필드를 기준으로 줄 단위로 오름차순 정렬 • -r 옵션을 사용하여 내림차순으로 정렬 • 정렬 필드 지정 형식:+시작필드 –종료필드 $ sort [-옵션] 파일*

  21. 정렬 예1 • $ sort you But when you come and I am filled with wonder, Each restless heart beats so imperfectly; I am strong, when I am on your shoulders Sometimes, I think I glimpse eternity Then, I am still and wait here in the silence There is no life - no life without its hunger; Until you come and sit awhile with me When I am down and, oh my soul, so weary When troubles come and my heart burdened be You raise me up, so I can stand on mountains You raise me up, to more than I can be You raise me up, to walk on stormy seas

  22. 정렬 예2 • $ sort +2 -3 you Then, I am still and wait here in the silence When I am down and, oh my soul, so weary Until you come and sit awhile with me When troubles come and my heart burdened be Each restless heart beats so imperfectly; You raise me up, so I can stand on mountains You raise me up, to more than I can be You raise me up, to walk on stormy seas There is no life - no life without its hunger; I am strong, when I am on your shoulders Sometimes, I think I glimpse eternity But when you come and I am filled with wonder,

  23. 파일 자르기: split 명령어 • 하나의 파일을 일정한 크기의 여러 개 작은 파일로 분할 $ split [-옵션] 입력파일 [출력파일] 1000줄씩 분할하여 xaa, xab, ... 형태의 파일명으로 저장 -l n 옵션: 분할할 줄 수를 지정 • 예 $ split -l 10 you $ ls -l -rw-r--r-- 1 mysung faculty 341 2월 16일 14:36 xaa -rw-r--r-- 1 mysung faculty 177 2월 16일 14:36 xab -rw-r--r-- 1 mysung faculty 518 2월 15일 19:33 you

  24. vi 편집: me When I am down and, oh my soul, so weary When troubles come and my heart burdened be Then, I am still and wait here in the silence Until you come and sit awhile with me You raise me up, so I can stand on mountains You raise me up, to walk on stormy seas I am strong, when I am on your shoulders You raise me up, to more than I can be You raise me up, so I can stand on mountains You raise me up, to walk on stormy seas I am strong, when I am on your shoulders There is no life - no life without its hunger; Each restless heart beats so imperfectly; But when you come and I am filled with wonder, Sometimes, I think I glimpse eternity

  25. 파일 비교: cmp 명령어 • $ cmp파일1 파일2 • 두 파일이 같은지 비교한다. • 두 파일이 같으면 아무 것도 출력하지 않음. • 두 파일이 서로 다르면 서로 달라지는 위치 출력 • $ cmp you me you me 다름: 337 자, 11 행

  26. diff 명령어 • $ diff 파일1 파일2 • 두 파일을 줄 단위로 비교하여 그 차이를 출력 • -i옵션은 대소문자를 무시하여 비교 • 출력은 첫 번째 파일을 두 번째 파일 내용과 같도록 바꿀 수 있는 편집 명령어 형태 • $ diff you me 10a11,14 > > You raise me up, so I can stand on mountains > You raise me up, to walk on stormy seas > I am strong, when I am on your shoulders

  27. diff 출력: 편집 명령어 • 추가(a) 첫 번째 파일의 줄 n1 이후에 두 번째 파일의 n3부터 n4까지의 줄들을 추가 n1 a n3,n4 > 추가할 두 번째 파일의 줄들 • 삭제(d) 첫 번째 파일의 n1부터 n2까지의 줄들을 삭제하면 두 번째 파일의 줄 n3 이후와 서로 같다. n1,n2 d n3 < 삭제할 첫 번째 파일의 줄들 • 변경(c) 첫 번째 파일의 n1부터 n2까지의 줄들을 두 번째 파일의 n3부터 n4까지의 줄들로 대치하면 두 파일은 서로 같다. n1,n2 c n3,n4 < 첫 번째 파일의 대치될 줄들 -- > 두 번째 파일의 대치할 줄들

  28. 링크 • 기존의 파일에 또 하나의 새로운 이름 혹은 경로 • 하드 링크 • 심볼릭 링크 (-s 옵션) $ ln [-s] 파일1 [파일2] $ ln [-s] 파일+ 디렉터리 • 하드 링크(hard link) $ ln hello hi $ ls -l 131092 -rw-rw-r--. 2 mysungmysung11 2013-10-15 13:52 hello 131092 -rw-rw-r--. 2 mysungmysung11 2013-10-15 13:52 hi

  29. 심볼릭 링크(symbolic link) • 심볼릭 링크 • 다른 파일을 가리키고 있는 별개의 파일이다 • 원래 파일의 위치에 대한 정보가 들어 있어서, • 심볼릭 링크를 참조하면, 가리키고 있는 파일을 대신 참조 $ ln -s hello hihi $ ls -il 131092 -rw-rw-r--. 2 mysungmysung11 2013-10-15 13:52 hello 131092 -rw-rw-r--. 2 mysungmysung11 2013-10-15 13:52 hi 131093 lrwxrwxrwx. 1 mysungmysung 5 2013-10-16 11:28 hihi -> hello

  30. 파일 찾기: find 명령어 • find 명령어 • 옵션의 검색 조건에 따라 대상 디렉터리 밑에서 해당되는 파일을 모두 찾아 출력 • $ find 디렉터리 [-옵션]

  31. find 명령어 예 $ find /usr -name‘*.c’ -print /usr밑에 .c 파일들을 찾아 경로명 출력 $ find . -name xx -ls이름이 xx인 파일을 찾아 ls명령어 수행 $ find . -type d -print 디렉터리(d) 파일을 찾아 경로명을 출력 $ find . -perm 700 -ls사용권한 700인 파일 찾아 ls명령어 수행 $ find . -size +1024c –ls 1024 바이트이상인 파일을 찾아 출력 $ find / -name core -size +1024 –ls파일 이름이 core 이고 크기가 1024 블록(512-byte) 이상인 파일을 찾아 ls명령어 수행 $ find . -user mysung -print 파일 소유자가 mysung인 파일을 찾아 출력 $ find . -atime +3 -print 3일 이전에 접근되었던 파일을 찾아 출력 $ find . -mtime -7 -print 7일 이내에 수정된 적이 있는 파일들 출력 $ find . -name xx -exec rm -i {} \; (i: interactive) 이름이 core인 파일에 대해 rm명령어 수행 $ find . -name ‘h*’-atime -3 -exec ls -il {} \; -exec cat {} ‘;’ 3일 이내에 접근된 파일 중 h*를 찾아 ls -il명령어 수행

  32. 5.2 명령어 스케줄링

  33. cron 시스템 • cron시스템 • 유닉스의 명령어 스케줄링 시스템으로 • crontab파일에 명시된 대로 주기적으로 명령을 수행한다 • crontab명령어 • $ crontab파일cronfile파일을 cron시스템에 등록 • $ crontab -l [사용자]사용자의 등록된 crontab파일 리스트 • $ crontab -e [사용자] 사용자의 등록된 crontab파일 수정/생성 • $ crontab -r [사용자] 사용자의 등록된 crontab파일 삭제 • crontab파일 • 7개의 필드로 구성 • 분 시 일 월 요일 [사용자] 명령

  34. 명령 스케줄링 crontab • crontab화일의 형식 minute (0-59) hour (0-23) day (1-31) month (1-12) weekday (1-7, 1=Mon, 2=Tue, 3=Wed, 4=Thu, 5=Fri, 6=Sat, 7=Sun) command Linux 명령어 • 처음 다섯 항목에 *가 오면 항상 일치됨을 의미 • 명령의 표준 출력은 자동적으로 사용자에게 mail utility를 통하여 전송 • % 다음의 문자는 임시 파일에 복사되고, 명령의 표준 입력으로 사용됨 (예) $ tty /dev/pts/? $ crontab * * * * * date > /dev/pts/? ^D $ crontab –e $ crontab–ㅣ $ crontab –r # 반드시 실행 PTM: pseudoterminal master PTS: pseudoterminal slave

  35. crontab 파일 예 • $ tty • /dev/pts/? • $ vi cronfile _____________________________________________________________ * * * * * echo one minute passed > /dev/pts/? ________________________________________________________________ • $ crontabcronfile • 다른 crontab파일의 예 20 1 * * * root find /tmp -atime +3 -exec rm -f {} ';' 매일 새벽 1시 20분에 3일간 접근하지 않은 /tmp내의 파일을 삭제 30 1 * 2,4,6,8,10,12 3-5 /usr/bin/wall /var/tmp/message 2개월마다 수요일부터 금요일까지 1시 30분에 wall 명령을 사용해서 시스템의 모든 사용자에게 메시지를 전송

  36. at 명령어 • at 명령어 • 미래의 특정 시간에 지정한 명령어가 한 번 실행되도록 한다. • 실행할 명령은 표준입력을 통해서 받는다. • $ at [-옵션] 시간 • (예) $ at 23:59 Oct 31 at> sort infile > outfile at> <EOT> • (예) $ tty # 자신의 가상 터미널 pts 번호확인 /dev/pts/? $ at now +1 minutes [ Enter ] at> date > /dev/pts/? at> ^D $ vi atfile date > /dev/pts/? at now +1 minutes < atfile # Reschedule Script $ at -l $ atrm job번호 # 반드시실행

  37. 5.3 디스크 및 아카이브

  38. df유틸리티 • $ df파일시스템* (free disk blocks) • 파일시스템에 대한 정보(사용중/사용 가능한 디스크 공간) • $ df Filesystem 1K-blocks Used Available Use% Mounted on rootfs 37468172 14309252 21281316 41% / udev 1803096 0 1803096 0% /dev tmpfs 1811008 1020 1809988 1% /dev/shm tmpfs 1811008 1328 1809680 1% /run /dev/mapper/VolGroup-lv_root 37468172 14309252 21281316 41% / tmpfs 1811008 0 1811008 0% /sys/fs/cgroup tmpfs 1811008 1328 1809680 1% /var/run tmpfs 1811008 1328 1809680 1% /var/lock tmpfs 1811008 0 1811008 0% /media /dev/sdb1 508745 118573 364572 25% /boot /dev/mapper/VolGroup-lv_home 34258832 1501428 31040364 5% /home • (cf.) fsck유틸리티 • $ fsck파일시스템* • 파일시스템을점검하고 수리한다 (root만 가능) • 관련 파일 /etc/fstab

  39. (참고) LinuxDisk Drive Naming • Old IDE = Parallel ATA(Advanced Technology Attachment) Naming • /dev/hda: the first drive (master) on the first IDE controller • /dev/hdb: the second drive (slave) on the first IDE controller • /dev/hdc: the fist (master) drive on the second IDE controller • /dev/hdd: the second (slave) drive on the second IDE controller • SATA = Serial ATA(Advanced Technology Attachment) controller • /dev/sda: the first drive (master) on the first SATA controller • /dev/sdb: the second drive (slave) on the first SATA controller • /dev/sdc: the fist (master) drive on the second SATA controller • /dev/sdd: the second (slave) drive on the second SATA controller

  40. du 유틸리티 • $ du [-s] 파일명* • 파일의 디스크 사용량을 블록단위로 보여준다 블록의크기는 ? • 파일을 명시하면 해당 파일의 사용량을 아니면 • 현재 디렉터리 내의 모든 파일들의 사용량을 보여준다 • $ du 16 ./kernelprog 852 ./ulprog 4 ./sysprog/tmp 672 ./sysprog 316 ./netprog 312 ./shellprog 2172 . • $ du –s--summarize(sum) 2172 . • $ du –b --bytes • $ du –k --kilobytes • $ du –l --count links • $ du –D --dereference-args • $ du –S --separate-dirs

  41. 아카이브 • 아카이브 • 백업 또는 다른 장소로의 이동을 위해 여러 파일들을 하나로 묶어놓은 묶음 • 아카이브를 만들거나 푸는데 tar(tape archive) 명령어 사용 • tar 명령어 • 옵션: c(create), v(verbose), x(extract), t(table of contents), f(file) • $ tar -cvf타르파일 파일+ 여러 파일들을 하나의 타르 파일로 묶으며 보통 확장자로.tar 사용 • $ tar -xvf타르파일 하나의 타르 파일을 풀어서 원래 파일들을 복원 • $ tar -tvf타르파일 타르 파일의 내용을 확인

  42. 아카이브: 예 • 현재 디렉터리에 있는 모든 파일을 다른 곳으로 옮기기 $ tar -cvf bu.tar * (또는 .) $ tar -tvfbu.tar $ tar -rvf bu.tar xx $ touch xx (파일의atimectime을 현재 시간으로 바꿈) $ tar -uvf bu.tar xx • bu.tar를 다른 곳으로 이동 $ mkdirtmp ; mvbu.tar tmp ; cd tmp ; pwd ; ls $ tar -tvfbu.tar $ tar -xvfbu.tar $ rm xx ; ls $ tar -xvf bu.tar xx ; ls • 파일 이름에 – 나오면 표준 출력 또는 표준 입력 $ cd .. ; rm–rftmp $ mkdirtmp $ tar cvf - . | ( cd tmp ; tar xvf - ) $ ls –l tmp ; rm –rftmp

  43. 화일압축 zip • zip –r –v { fileName }+ [ Unix & Linux ] –v 압축되는 상황을 보여 줌 –r 디렉토리일경우 재귀적으로(recursively) –n 디렉토리 내의 지정된확장자를 가진 파일을 제외하고 압축 –x 디렉토리 내의 지정된파일 을 제외하고 압축 • unzip –v { fileName }+ –l 압축파일의 목록만 출력 (stdout) –p 화일 변환 없이 내용을 파이프로 출력 (stdout) –c 화일 변환 없이 파일명과 내용을 파이프로출력 (stdout) –d 지정된 디렉토리에 추출 (예) $zip –rv dd.zip dd(디렉토리) $ zip –rv bu.zip * (소문자 .zip 확장자) $ mkdirtmp ; mv bu.zip tmp ; cd tmp ; pwd ; ls $ unzip bu.zip $ unzip bu.zip [ –d tmp ]

  44. 파일압축gzip&compress • gzip명령어[ Unix & Linux ] $ gzip파일* $ gzip -d 파일.gz*  gunzip과 동일 • gzip –r –v { fileName }+ –v 압축되는 상황을 보여 줌 –r 디렉토리일경우 재귀적으로(recursively) –c 압축된 파일로 원래의 파일을 덮어쓰지 않고 표준 출력으로 내보냄 -l압축된 파일의 압축률 등 압축 정보를 보여줌 (예) $ gzip –rv * $ gunzip –rv *또는$ gzip -d –rv * • compress / uncpmpress명령어 [ UnixOnly ] $ compress 파일* $ uncompress파일.Z* (대문자 .Z 확장자)

  45. 압축 예 • 사용 방법 • 파일들을 하나의 타르파일로 묶은 후 compress/gzip을 사용해 압축 • 파일 복원: 압축을 해제한 후, 타르 파일을 풀어서 원래 파일들을 복원 • 사용예 $ tar -cvf bu.tar * $ gzip bu.tar 또는 $ tar-czvf bu.tar.gz * • 이 파일을 원하는 곳으로 이동 $ gzip -d bu.tar.gz $ tar -xvf bu.tar

  46. 5.4 AWK

  47. AWK • AWK • 일반 스크립트 언어 • AWK(Aho, Weinberger, Kernighan) • 텍스트 형태로 되어있는 줄을 필드로 구분하여 처리한다 • 필드는 일단은 줄을 구성하는 단어 정도로 생각하자 • awk프로그램 • 간단한 프로그램은 명령줄에 직접 작성하여 수행 • awk프로그램을 파일로 작성하여 -f 옵션을 이용하여 수행 $ awk [-Fc] 프로그램 파일* $ awk [-Fc] [-f 프로그램파일] 파일*

  48. awk 프로그램 • awk프로그램 • 조건과 액션을 기술하는 명령어들로 구성됨 • [ 조건 ] [ { 액션 } ] • 대상 파일의 줄들을 스캔하여 조건을 만족하는 줄에 액션 수행 $ awk ‘{ print NF, $0 }’ you $ awk ‘{ print $1, $3, $NF }’ you $ awk ‘NR > 1 && NR < 4 { print NR, $1, $3, $NF }’ you

  49. 조건과 액션 • 조건(condition) • BEGIN // 파일 시작 • END // 파일 끝 • 관계 연산자 혹은 논리 연산자를 포함한 조건식 • /패턴/ 패턴에 해당하는 줄 • 패턴1, 패턴2 패턴1을 포함한 줄부터 패턴2를 포함한 줄까지 • 액션(action) • if (조건) 실행문[else 실행문] • while (조건) 실행문 • for (식; 조건; 식) 실행문 • break • continue • 변수 = 식 • print [식들의 리스트] • printf포맷 [, 식들의 리스트] • next 현재 줄에 대한 나머지 패턴 건너뛰기 • exit 현재 줄의 나머지 부분 건너뛰기 • {실행문 리스트}

  50. awk프로그램 예 • [예제 1] $ viawk1 BEGIN { print "파일 시작:", FILENAME } { print $1, $NF } END { print "파일 끝" } $ awk–f awk1 you • [예제 2] $ viawk2 BEGIN { print "파일 시작" } { printf "line %d: %d \n", NR, NF; line++; word += NF } END { printf "줄 수 = %d, 단어 수 = %d\n", line, word }

More Related