파일 조작 파일 조작 filtering, sorting, comparing, searching for files 명령어 스케줄링


Download 445 b.
Sana11.07.2017
Hajmi445 b.
#10961



파일 조작

  • 파일 조작

    • filtering, sorting, comparing, searching for files
  • 명령어 스케줄링

    • cron, at
  • 텍스트 처리 프로그램

    • AWK
  • 파일 보관 및 압축

    • archiving
    • tar, gzip




  • filter all lines containing a specified pattern



    • %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


Sorting files

  • Sorting files

  • sort -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


    • %sort -r sortfile
    • %sort +0 -1 sortfile
    • %sort +0 -1 -bM sortfile
    • %cmp lady1 lady2
    • %cmp -l lady1 lady2
    • %diff lady1 lady2


find pathList expression

  • find pathList expression

  • recursively descends through pathList and applies expression to every file.

  • expression

  • -name pattern

  • -user userId

  • -atime count

  • -print

  • -ls

  • -exec command



  • %find . -name '*.c' -print

  • %find . -user chang -ls

  • %find . -mtime 14 -ls

  • %find . -mtime 14 -ls -exec rm {} \;











Unix에서 처음 개발된 일반 스크립트 언어

  • Unix에서 처음 개발된 일반 스크립트 언어

  • 텍스트 형태로 되어있는 데이터를 필드로 구분하여 처리하는 기능을 기본으로 한다.

  • Alfred Aho, Peter Weinberger, Brian Kernighan



  • 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 } ]

  • Examples

  • awk ‘{ print NF, $0}’ float

  • awk ‘{ print $1 $3 $NF}’ float

  • awk ‘NR > 1 && NR <4 { print NR, $1, $3, $NF}’ float



Condition

  • Condition



Action

  • Action

    • if (conditional) statement [else statement]
    • while (conditional) statement
    • for (expression; conditional; expression) statement
    • break
    • continue
    • variable=expression


Action

  • 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}


awk2

  • 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

  • }



awk5

  • awk5

  • {for (I = NF; I >= 1; I--)

  • printf “%s “, $I

  • printf “\n”

  • }

  • awk6

  • /t.*e/ {print $0}

  • awk7

  • /strong/, /clear/ { print $0}





three utilities to archive files

  • 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


% tar -cvf tarfile .

      • % tar -cvf tarfile .
      • % tar -xvf tarfile
      • % tar -rvf tarfile reverse.c
      • % tar -cvf /dev/rst0 *


compress -cv {fileName}+

  • 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



gzip {fileName}+

  • 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



Download 445 b.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling