תרגול מס' 1

Embed Size (px)

DESCRIPTION

תרגול מס' 1. מערכת ההפעלה UNIX תכניות סטנדרטיות ב UNIX שרשור פקודות באמצעות Pipeline עבודה ב- bash. עבודה בסביבת UNIX. מהי מערכת הפעלה? מערכת הקבצים ב- UNIX עבודה בחלון Shell. מהי מערכת הפעלה?. מערכת הפעלה מהווה שכבת ביניים בין החומרה לבין התוכנה - PowerPoint PPT Presentation

Text of תרגול מס' 1

PowerPoint Presentation

' 1 UNIX UNIX Pipeline - bash1 UNIX ? -UNIX Shell

- 23412222 ? : : ,

: WindowsUbuntuOSXAndroidiOS

- 2341223

3 UNIX?UNIX

( POSIX)

UNIX Linux Windows

- -t2 Linux.

- 2341224 -UNIX . , , ( ). Ubuntu Android, , . Red Hat.

( , Android )

4 -UNIX -UNIX -Windows (Directory) ( ) . test.c C -UNIX ( exe -Windows)

- 2341225

- Directory . . : Directory, Folder, , . -UNIX case sensitive -Windows.

- 256 . / .5

"/"

" :/usr/mtm/exercise1/main.c "/"

:main.c /usr/mtm/exercise1exercise1/main.c /usr/mtm

- 23412266 UNIX

- 2341227 mtm ( -t2 ) : /staff/015/mtm

7 :. - .. - ~ - ~user - user ~mtm t2

* " , :* *.txt -".txt" - 23412288 -UNIX: ?/usr/uri/progs/Hello.c/usr/uri/progs/Matamprogs~/progs./hw1../hw2~ari/progs~mtm/public/1011a/ex1~/progs/*

- 2341229 / (root)MatamusrtmpariuriprogsprogsHello.cbinhw1hw29Pipeline Pipeline - 23412210

ls -more:> ls -l > tmp> more < tmp> rm tmp - 23412211

Pipeline -pipeline | :> ls -l | more :> command1| command2| command3 - 23412212command1stdoutcommand2stdinstdoutcommand3stdinPipeline - | ' ' pipeline - 23412213 -UNIXheadtailsortuniqgrep

- 23412214mkdir rmdircatmoreless

cutwctee echoprintflscpmvrmpwdcd -UNIX

UNIX

" :> [options] [input file] , , (?)"

" man - 23412215 -pipeline.15 -UNIX ls:> ls [flags] [files] ls

: -l ls -a -UNIX -. () - " ls -a -l ls -al - 2341221616ls - >lshello.c private/ story.txt>ls privateexample.txt>ls -ltotal 12-rw-r--r-- 1 mtm users 3047 Jun 20 10:35 hello.cdrwx------ 2 mtm users 4096 Sep 1 14:28 private/-rw------- 1 mtm users 1081 Sep 1 14:28 story.txt>ls -altotal 28drwx------ 3 mtm users 4096 Sep 1 14:29 ./drwx--x--x 50 mtm users 12288 Sep 1 10:52 ../-rw-r--r-- 1 mtm users 3047 Jun 20 10:35 hello.cdrwx------ 2 mtm users 4096 Sep 1 14:28 private/-rw------- 1 mtm users 1081 Sep 1 14:28 story.txt

- 2341221717 " pwd:> pwd " cd:> cd " mkdir:> mkdir " rmdir:> rmdir

- 2341221818 - >cd ~>pwd/usr/030/moshe>cd matammatam: No such file or directory.>mkdir matam>cd matam>pwd/usr/030/moshe/matam>cd ..>rmdir matam

- 23412219 ~ , .. - . , . : No such file or directory - Command not found - , "./" ( )Permission denied - , .19 - 2341222020 - 2341222121 rm :> rm [ options ] :-r: -i: -f:

:

:> rm -rf *

- 2341222222 - >lshello.c private/ story.txt>cp hello.c prog.c>lshello.c private/ prog.c story.txt>mv prog.c private/program.c>lshello.c private/ story.txt>ls privateexample.txt program.c>mv hello.c story.txt private>lsprivate/ - 2341222323 - >ls privateexample.txt hello.c program.c story.txt>rm -i private/story.txt rm: remove regular file `private/story.txt'? y>rm privaterm: cannot remove directory `private': Is a directory>rm -ri privaterm: descend into directory `private'? n>rm -rf private>ls> - 2341222424 cat > cat (" )

more , > more enter q

less more > less - 2341222525 head head :> head [-n#] [files] # 10 # -# - 23412226a line 1a line 2a line 3a line 4a line 5a_fileb line 1b line 2b line 3b_file> head n+2 a_filea line 1a line 2> head n+1 < b_fileb line 1> head n-2 a_file b_file==> a_file b_file tail [-/+#] [files] -# # +# -# 10

2-3 ? - 23412227a line 1a line 2a line 3a line 4a line 5a_fileb line 1b line 2b line 3b_file> tail -2 a_filea line 4a line 5> tail +2 a_filea line 2a line 3a line 4a line 5> tail -1 a_file b_file==> a_file b_file head n+3 a_file | tail -2a line 2a line 3 sort sort ( )> sort [options] [files]-n: -r: ( )-k#: -# -1-f: uppercase/lowercase sort -b: -s: - - 23412228sort - - 23412229> sort dataFatherWorldforwho> sort -f dataFatherforwhoWorld> sort -r datawhoforWorldFathersort -rf dataWorldwhoforFather> ls -ltotal 4-rw------- 1 romano root 520 Nov 8 23:09 data-rw------- 1 romano 368 43 Nov 8 23:12 ex1-rw------- 1 romano 368 428 Nov 8 23:22 ex2-rw------- 1 romano 368 322 Nov 10 13:30 ex3> ls -l | sort -rnk5-rw------- 1 romano root 520 Nov 8 23:09 data-rw------- 1 romano 368 428 Nov 8 23:22 ex2-rw------- 1 romano 368 322 Nov 10 13:30 ex3-rw------- 1 romano 368 43 Nov 8 23:12 ex1total 4

WorldwhoforFatherdata211numbers> sort numbers112> sort -n numbers211 uniq uniq > uniq [options] [input [output]] - -c: -d: -u: -c/-d/-u -#: -# ( ) - 2341223030uniq - - 23412231> uniq file3onetwothreeone> uniq file3 list> cat listonetwothreeone> uniq sentencesThis is sparta!It is sparta!Bye bye sparta!> uniq -1 sentencesThis is sparta!Bye bye sparta!> uniq -2 sentencesThis is sparta!

UriDanUriElenaAlexOfraUriOfranamesonetwotwothreethreethreeoneonefile3> sort names | uniqAlexDanElenaOfraUri> sort names | uniq -uAlexDanElena> sort names | uniq -dOfraUri> sort names | uniq -c 1 Alex 1 Dan 1 Elena 2 Ofra 3 Uri

This is sparta!It is sparta!Bye bye sparta!sentences grep grep > grep [options] [files] -v: -i: uppercase/lowercase:-w ( ) -w expression .-n: -l: -c: : ^ $ , -man grep

- 2341223232grep - - 23412233> grep cow farm1cow Betsyslim cow Dazytwo cows Dartsy & Teo> grep -v cow farm1goat UptonFat Cow Burgerhorse Admiral> grep -i cow farm1cow Betsyslim cow DazyFat Cow Burgertwo cows Dartsy & Teo> grep -w cow farm1cow Betsyslim cow Dazy> grep "slim cow" farm1slim cow Dazy> grep ^cow farm1cow Betsy

goat Uptoncow Betsyslim cow DazyFat Cow Burgertwo cows Dartsy & Teohorse Admiralfarm1> grep cow farm1 farm2farm1:cow Betsyfarm1:slim cow Dazyfarm1:two cows Dartsy & Teofarm2:cow Lenifarm2:cow Oreo> grep -n cow farm1 farm2farm1:2:cow Betsyfarm1:3:slim cow Dazyfarm1:5:two cows Dartsy & Teofarm2:2:cow Lenifarm2:4:cow Oreo> grep -l cow farm1 farm2farm1farm2> grep -c cow farm1 farm2farm1:3farm2:2> grep o$ farm1two cows Dartsy & Teo

sheep Brookcow Lenigoat Astercow Oreofarm2 cut cut > cut [files]-c: -f: " Tab -d"?": ( -f) , " - (): -c1,2,5-6,10- , 1, 2, 5, 6, -10 - 23412234cut - - 23412235> cut -c1-3,5,8-10 file1a11a a1b21b b2c31c c3> cut -d" " -f2,4 file1a12 a14b22 b24c32 c34> cut -d":" f1 file2a11b21c31 c32 c33> cut -d":" f2-3 file2a12:a13b22c31 c32 c33> cut -d" " -f-2,4- file1a11 a12 a14 a15b21 b22 b24 b25c31 c32 c34 c35

a11 a12 a13 a14 a15b21 b22 b23 b24 b25c31 c32 c33 c34 c35file1a11:a12:a13 b21:b22 c31 c32 c33 file235 wc wc , > wc [options] [files]-c: -l: -w: wc - 23412236> wc -w war_and_peace590234 war_and_peace> wc -l war_and_peace55480 war_and_peace> wc -c war_and_peace3348543 war_and_peace> wc mtm_ex2.h 120 641 4161 mtm_ex2.h> wc mtm_ex2.h parsing_example.c 120 641 4161 mtm_ex2.h 136 692 4543 parsing_example.c 256 1333 8704 total

tee tee > tee [options] [files] [files]-a: , - 23412237

> head -3 a_file | tee file1 file2 | tail -2a line 2a line 3> cat file1a line 1a line 2a line 3From http://commons.wikimedia.org/wiki/File:KF_25_Tee.jpg Creative Commons License

37 printf printf -C> printf [arguments]%s: %[-]m[.n]s: m n . - ().

- 23412238> printf "%s %s! \n" Hello worldHello world!

> printf "%-10s %.5s\n" Hello world.Hello world!

, .printf echo , echo .38 -UNIX - -Unix " head -tail sort uniq grep cut wc tee printf - 23412239 -Bash bash -bash - 2341224040 echo , echo echo > echo [-n] [words]-n:

- 23412241> echo Hello world!Hello world!

>> echo n Hello world!Hello world!> n 41 - alias alias -Shell> alias ="" '=' .-Shell alias alias unalias

- 23412242< alias ll="ls l"> ll-rw-r--r-- 1 user staff 0 Nov 13 15:14 a.c> alias cdex2="cd ~/mtm/ex2"> cdex2> alias GCC="gcc -std=c99 -Wall -Werror -pednatic-errors"> GCC hello.c -o hello> unalias GCC> GCC hello.c -o hello-bash:GCC: Command not found.Filename Expansion . bash * ( ) ? -[ ] , a-z { }

- 23412243< lsaxb.c a3b.c cab.txt a4b.txt> echo files: *files: axb.c a3b.c cab.txt a4b.txt> echo The source files are *.cThe source fi