Presentation is loading. Please wait.

Presentation is loading. Please wait.

IT244 - Introduction to Linux / Unix Instructor: Bo Sheng

Similar presentations


Presentation on theme: "IT244 - Introduction to Linux / Unix Instructor: Bo Sheng"— Presentation transcript:

1 IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
Shell (ch 5) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng

2 Outline Command line syntax and processing
Standard I/O and device files Redirection and pipes

3 Command Line Syntax Arguments command [arg1] [arg2] … [argn] RETURN
Separated by space Could be optional ls ls -l cp hello hello.copy command [arg1] [arg2] … [argn] RETURN

4 Command Line Syntax Arguments (options) ls –l, rm –i Combining options
ls -l -r = ls –lr Option arguments gcc -o hello hello.c

5 Command Line Syntax Non-option arguments starting with ‘-’
Create a file ‘-l’ and then list it ls –l ls ./-l, ls -- -l Create a file ‘-i’ and then delete it rm –i rm ./-i, rm -- -i

6 Command Line Processing
e.g., /bin/ls Arguments are processed by programs, NOT the shell

7 Standard I/O

8 Standard I/O

9 Device Files The screen and keyboard as a file who, w cat
CTRL+D (EOF) to terminate

10 Device Files The screen and keyboard as a file
An example with two terminals Use “who” to find out their device files, e.g., /dev/pts/1 and /dev/pts/2 In terminal 2, type in echo hello > /dev/pts/1 cat /dev/pts/1 Then type in terminal 1

11 Redirection Redirecting standard output ( > )
command [arguments] > filename

12 Redirection Redirecting standard output ( > ) Examples
echo hello world > hello cat > sample cat hello > sample cat days months > sample

13 Redirection Redirecting standard output ( > ) Examples
ls > filelist Append (>>) echo append >> hello

14 Redirection Redirecting standard input ( < )
command [arguments] < filename

15 Pipes and Redirection command1 [arguments] | command2 [arguments]
command1 [arguments] > temp command2[arguments] < temp rm temp

16 Some New Utilities Translate (tr) tr abc ABC tr hld xyz < hello
tr “[A-Z]” “[a-z]” linux Examples cat month colors.1|tr “[A-Z]” “[a-z]” | sort

17 Some New Utilities Split directions (tee) tee filename
ls –l | tee filelist cat colors.1 | tee file1 > file2 grep e colors.1 | tee /dev/pts/1 | sort

18 More Examples Use tr to replace or delete characters
echo “this is a test” > test wc -c test tr -d “ ” < test | wc –c

19 More Examples Redirection echo “***” >> hello
Insert a line before the first line echo “***” > temp cat temp hello > hello.new mv hello.new hello cat hello >> temp mv temp hello cat temp hello > hello ?

20 Filename Generation/Wildcards
“*” and “?” “?” : single character “*” : any number of characters (including 0) ls colors.? echo col* ls hello*

21 Filename Generation/Wildcards
Examples echo ????? echo ~/.* cat hello*

22 Filename Generation/Wildcards
“[]” for range echo [aeiou]* cat colors.[135] echo [a-z]* echo *[a-l] “^” for “not” echo *[^a-z] echo [^a-o]*

23 Execute Commands Foreground and background jobs
cp ~shengbo/it244/exetest . ./exetest (CTRL+C to terminate) ./exetest & (running in background) jobs

24 Execute Commands Foreground and background jobs Multitasking
One foreground in a terminal Only foreground gets input from keyboard Multitasking

25 Execute Commands Job number / PID number Job number Process ID

26 Execute Commands Job number / PID number Job number Process ID

27 Execute Commands Suspend a foreground job ./exetest CTRL+Z jobs
Different from a running background job

28 Execute Commands Resume a suspended job In the background
bg [%job_number] In the foreground fg [%job_number] Bring background job to foreground

29 Execute Commands Abort a job Foreground Background CTRL+C
kill process_ID kill %job_number tail –f hello &


Download ppt "IT244 - Introduction to Linux / Unix Instructor: Bo Sheng"

Similar presentations


Ads by Google