1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting,...
DESCRIPTION
파일 조작 3TRANSCRIPT
![Page 1: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/1.jpg)
1
제 3 장 유틸리티
숙명여대 창병모2009.09
![Page 2: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/2.jpg)
2
파일 조작 filtering, sorting, comparing, searching for
files 명령어 스케줄링
cron, at 텍스트 처리 프로그램
AWK 파일 보관 및 압축
archiving tar, gzip
유용한 유틸리티
![Page 3: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/3.jpg)
파일 조작
3
![Page 4: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/4.jpg)
4
filter all lines containing a specified pattern
grep -hilnvw pattern {fileName}*fgrep -hilnvwx string {fileName}*egrep-hilnvw pattern {fileName}*
Utility Kind of patternfgrep fixed string only
grep regular expression
egrep Extended regular expression
파일 필터링
![Page 5: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/5.jpg)
5
%grep -wn the grepfile
%grep -wnv the grepfile
%grep -w x *.c
%grep -wl x *.c
%grep “.nd” grepfile
%grep “sm.*ng” grepfile
%grep “[a-m]nd” grepfile
grep: 예
![Page 6: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/6.jpg)
6
Sorting filessort -tc -r {sortField -bfMn}* {fileName}*
- sorts files in ascending or descending order
- based on sort field(s)
Comparing files
cmp -ls fileName1 fileName2 testing for the sameness
diff -i -dflag fileName1 fileName2 file differences
파일 정렬 /비교
![Page 7: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/7.jpg)
7
%sort -r sortfile
%sort +0 -1 sortfile
%sort +0 -1 -bM sortfile
%cmp lady1 lady2
%cmp -l lady1 lady2
%diff lady1 lady2
파일 정렬 /비교 : 예
![Page 8: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/8.jpg)
8
find pathList expressionrecursively descends through pathList and applies expression to every file.
expression-name pattern-user userId-atime count-print-ls-exec command
파일 찾기
![Page 9: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/9.jpg)
9
%find . -name '*.c' -print
%find . -user chang -ls
%find . -mtime 14 -ls
%find . -mtime 14 -ls -exec rm {} \;
파일 찾기 : 예
![Page 10: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/10.jpg)
명령어 스케줄링
10
![Page 11: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/11.jpg)
11
What is cron system in UNIX ?- schedule a series of jobs to be executed on a periodic
basis using crontab (crontable)
crontab crontabNamecrontab -ler [userName]
1) crontab is the user interface to the cron system2) when used without any options, the crontab file calledcrontabName is registered and3) its commands are executed according to the specifiedtiming rules
주기적 실행 : cron
![Page 12: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/12.jpg)
12
Crontab file
minute hour day month
weekday command
0-59 0-23 1-31 1-12 1-7(1=Mon) UNIX command
example : a crontab file called crontab.cron
0 8 * * 1 echo Happy Monday Moring
* * * * * echo One Minute Passed >
/dev/tty1
30 14 1 * * mail users % Jan Meeting At 3 pm
주기적 실행 : cron
![Page 13: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/13.jpg)
텍스트 처리 프로그램 :AWK
13
![Page 14: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/14.jpg)
14
AWK Unix 에서 처음 개발된 일반
스크립트 언어
텍스트 형태로 되어있는 데이터를 필드로 구분하여 처리하는 기능을 기본으로 한다 .
Alfred Aho, Peter Weinberger, Brian Kernighan
![Page 15: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/15.jpg)
15
awk -Fc [-f fileName] program {fileName}*Scans the lines and performs actions on every line that matches a condition
awk program is a list of commands of the form[ condition] [ { action } ]
Examplesawk ‘{ print NF, $0}’ floatawk ‘{ print $1 $3 $NF}’ floatawk ‘NR > 1 && NR <4 { print NR, $1, $3, $NF}’ float
AWK
![Page 16: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/16.jpg)
16
AWK Condition
the special token BEGIN or END an expression involving logical operators,
relational operators, and/or regular expressions
![Page 17: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/17.jpg)
17
AWK Action
if (conditional) statement [else statement] while (conditional) statement for (expression; conditional; expression)
statement break continue variable=expression
![Page 18: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/18.jpg)
18
AWK Action
print [list of expressions] printf format [, list of expressions] next
skips the remaining patterns of the current line of input)
exit skips the rest of the current line)
{list of statements}
![Page 19: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/19.jpg)
19
awk2 BEGIN { print “Start of file:”, FILENAME }
{ print $1 $3 $NF }END { print “End of file” }
awk -f awk2 float awk4
BEGIN { print “Scanning file” }{ printf “line %d: %s\n”, NR, $0; lineCount++; wordCount + = NF}
AWK: 예
![Page 20: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/20.jpg)
20
awk5 {for (I = NF; I >= 1; I--)
printf “%s “, $Iprintf “\n”}
awk6/t.*e/ {print $0}
awk7/strong/, /clear/ { print $0}
AWK: 예
![Page 21: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/21.jpg)
파일 보관 /압축
21
![Page 22: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/22.jpg)
22
three utilities to archive files save files to a disk or tape tar, cpio, dump
tar maintain an archive of files on a magnetic tape create and access special tar-format archive files a file can be added on the end of tar-format file
tar -cfrtuvx [tarFileName] fileList
파일 보관
![Page 23: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/23.jpg)
23
% tar -cvf tarfile .
% tar -xvf tarfile
% tar -rvf tarfile reverse.c
% tar -cvf /dev/rst0 *
파일 보관 : 예
![Page 24: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/24.jpg)
24
compress -cv {fileName}+replaces a file by its compressed version(.Z)-c option sends the compressed version to standard output
uncompress -cv {fileName}+re-creating the original file from its compressed file
%compress -v a.c b.c%uncompress *.Z
파일 압축 : compress
![Page 25: 1 제 3 장 유틸리티 숙명여대 창병모 2009.09. 2 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링 cron, at 텍스트 처리 프로그램](https://reader036.vdocuments.site/reader036/viewer/2022081419/5a4d1b187f8b9ab05999297c/html5/thumbnails/25.jpg)
25
gzip {fileName}+replaces a file by its compressed version(.gz)-c option sends the compressed version to standard output
gzip -d {fileName}+decompress the original files from its compressed file
gzip -l {fileName}+list compressed file contents
%gzip -v a.c b.c%gzip –d *.gz
파일 압축 : gzip