Upload
brittney-burke
View
234
Download
0
Embed Size (px)
DESCRIPTION
파일 조작 3
Citation preview
1
제 3 장 유틸리티
숙명여대 창병모2009.09
2
파일 조작 filtering, sorting, comparing, searching for
files 명령어 스케줄링
cron, at 텍스트 처리 프로그램
AWK 파일 보관 및 압축
archiving tar, gzip
유용한 유틸리티
파일 조작
3
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
파일 필터링
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: 예
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
파일 정렬 /비교
7
%sort -r sortfile
%sort +0 -1 sortfile
%sort +0 -1 -bM sortfile
%cmp lady1 lady2
%cmp -l lady1 lady2
%diff lady1 lady2
파일 정렬 /비교 : 예
8
find pathList expressionrecursively descends through pathList and applies expression to every file.
expression-name pattern-user userId-atime count-print-ls-exec command
파일 찾기
9
%find . -name '*.c' -print
%find . -user chang -ls
%find . -mtime 14 -ls
%find . -mtime 14 -ls -exec rm {} \;
파일 찾기 : 예
명령어 스케줄링
10
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
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
텍스트 처리 프로그램 :AWK
13
14
AWK Unix 에서 처음 개발된 일반
스크립트 언어
텍스트 형태로 되어있는 데이터를 필드로 구분하여 처리하는 기능을 기본으로 한다 .
Alfred Aho, Peter Weinberger, Brian Kernighan
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
16
AWK Condition
the special token BEGIN or END an expression involving logical operators,
relational operators, and/or regular expressions
17
AWK Action
if (conditional) statement [else statement] while (conditional) statement for (expression; conditional; expression)
statement break continue variable=expression
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}
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: 예
20
awk5 {for (I = NF; I >= 1; I--)
printf “%s “, $Iprintf “\n”}
awk6/t.*e/ {print $0}
awk7/strong/, /clear/ { print $0}
AWK: 예
파일 보관 /압축
21
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
파일 보관
23
% tar -cvf tarfile .
% tar -xvf tarfile
% tar -rvf tarfile reverse.c
% tar -cvf /dev/rst0 *
파일 보관 : 예
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
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