14
+ Unix study class May,16 Ryota

Unix study class_01

Embed Size (px)

Citation preview

Page 1: Unix study class_01

+

Unix study class May,16Ryota

Page 2: Unix study class_01

+Windows and Mac

Graphical User Interface

Application is your solution.

Guaranteed quality.You must pay to use them.Made by corporations.

Page 3: Unix study class_01

+Unix and Unix-like OS(Linux)

Terminal.

Your program is your solution. bash

Highly flexible.Free.Made by communities.

Page 4: Unix study class_01

+But I can’t code a program myself…

I have no basis of math, algorithm or computer science and...

Fear not, for the communities with you.

Unix has• a lot of Utilities• a lot of Libraries • a lot of web sites where professionals answer for you.

You don’t (always) need to code everything by yourself because

How do we use Unix utilities?

Page 5: Unix study class_01

+Shell allows you to communicate with the OS

Shell

OS

Every OS has its shell.Windows -> explorer.exeMac -> Finder

Unix -> bash

bash receives your command and execute it.bash is programmable.bash includes many utilities.You almost always find bash on any Unix system.

Page 6: Unix study class_01

+The first command: echo

$ echo "hello world"hello world

What is it actually doing?Read the manual!

“It writes arguments to the standard output.”

What is standard output?It’s the key to combine Unix utilities.

$ man echo

Page 7: Unix study class_01

+The second command: tr

$ echo "hello world" | tr "o" "e"helle werld

“o” has been substituted for “e”.In other words, translating.

manual says..

“tr copies the standard input to the standard output with sub-stitution”

Page 8: Unix study class_01

+

hello world⬇️

helle werld

Pipe connects the commands.

echo “hello world” | tr “o” “e”

hello worldstdout stdin

stdout

pipe

Page 9: Unix study class_01

+Training

2. echo “hello world” | tr “o” “e” | tr “h” “H” | tr “w” “W”

1. echo “spam” | tr “s” “z”

3. echo “tomato” | tr –d “o”

4. echo "hello world" | tr " " "\n”hint: \n is a escaped character for newline

5. echo “hello world” | tr “lo” “ol”

Page 10: Unix study class_01

+More commands: cat

$ cat file_abaconspampizza

$ cat file_a file_bbaconspampizzatomatopotatolettuce

$ cat file_btomatopotatolettuce

concatenate and print files.

There is files named file_a and file_b.

Page 11: Unix study class_01

+More commands: sort

$ sort file_a file_bbaconlettucepizzapotatospamtomato

Write sorted concatenation of files to standard output.

sort can read from standard input.cat file_a file_b | sortThis command works same.

Alphabeticallysorted

Page 12: Unix study class_01

+More commands: cut

$ cat agesryota sugimoto 29takahide hayano 35itsuro inoue 58hirofumi nakaoka 34waleed omer 35shiro yamada 48kazuyoshi hosomichi 36

$ cut -f 3 ages29355534354836

cut out selected portions of each line of a file.

All values in this table are fiction.

Page 13: Unix study class_01

+More commands: uniq

$ cat file_cabbcaddd

$ uniq file_cabcad

report or filter out repeated lines in a file.

Page 14: Unix study class_01

+Training

1. cat file_a | tr "a" "A" | cat - file_b

2. Remove all duplicating lines from file_c.

3. Sort ages file by their family name.

4. Count the number of each ages from ages file.Hint: Use –c option of uniq command.