1 / 21

Lecture 8: Shell ( ch 5)

Lecture 8: Shell ( ch 5). IT244 - Introduction to Linux / Unix Instructor: Bo Sheng. Redirection. Redirecting standard output ( > ). command [arguments] > filename . Redirection. Redirecting standard output ( > ) Examples echo hello world > hello cat > sample cat hello > sample

ita
Download Presentation

Lecture 8: Shell ( ch 5)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Redirection • Redirecting standard output ( > ) command [arguments] > filename

  3. Redirection • Redirecting standard output ( > ) • Examples • echo hello world > hello • cat > sample • cat hello > sample • cat days months > sample

  4. Redirection • Redirecting standard output ( > ) • Examples • ls > filelist • Append (>>) • echo append >> hello

  5. Redirection • Redirecting standard input ( < ) command [arguments] < filename

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

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

  8. 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

  9. More Examples • Use tr to replace or delete characters • echo “this is a test” > test • wc -c test • tr -d “ ” < test | wc –c • Control characters count • echo hi(CTRL+V, CTRL+A) > hello • wc -c hello

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

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

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

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

  14. Filename Generation/Wildcards • Shell expands ambiguous filenames • ls hello? • ls hello\? The shell searches for matching filenames: hello1, hello2 hello1, hello2 ls hello? shell ls

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

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

  17. Execute Commands • Job number / PID number Job number Process ID

  18. Execute Commands • Job number / PID number Job number Process ID

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

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

  21. Execute Commands • Abort a job • Foreground • CTRL+C • Background • kill process_ID • tail –f hello &

More Related