Presentation is loading. Please wait.

Presentation is loading. Please wait.

EMT 2390L Lecture 4 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.

Similar presentations


Presentation on theme: "EMT 2390L Lecture 4 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts."— Presentation transcript:

1 EMT 2390L Lecture 4 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts

2 Outline Redirection Pipelines Patterns Expansions Shell Arithmetic Brace Expansion Escape Characters

3 Redirection stdout – default output stream To redirect output from stdout use > o ls -l /usr/bin > ls-output.txt o less ls-output.txt To redirect and append use >> o ls -l /usr/bin >> ls-output.txt cat – reads one or more files and copies them to standard output o Usage: cat file1 file2 … fileN o cat > lazy_dog.txt o cat lazy_dog.txt To redirect input use < o cat < lazy_dog.txt

4 Pipelines Pipelines allows you to redirect the output of one command and pipe it as input to another The operator is the vertical bar | o Usage: command1 | command2 | … | commandN o ls -l /usr/bin | less sort – sorts the input o ls /bin /usr/bin | sort | less uniq – removes duplicates o ls /bin /usr/bin | sort | uniq | less o ls /bin /usr/bin | sort | uniq -d | less wc - command used to display the number of lines, words, and bytes contained in files. o wc ls-output.txt

5 Patterns grep – a powerful program that allows you to find text patterns within files. When grep finds the pattern, it prints out the lines containing it. o ls /bin /usr/bin | sort | uniq | grep zip head - prints the first 10 lines of a file o head ls-output.txt o head -n 5 ls-output.txt tail - prints the last 10 lines of a file o tail ls-output.txt o tail -n 5 ls-output.txt o tail -f /var/log/messages //Real-time monitoring, exit with ctrl+C tee - reads standard input and copies it to both standard output and to one or more files o ls /usr/bin | tee ls.txt o ls /usr/bin | tee ls.txt | grep zip

6 Expansion echo – command used to display a line of text o echo Hello When using wildcards and certain commands with special meaning, Linux “expand” these command before executing them o echo * o echo D* o echo *s o echo ~

7 Shell Arithmetic Uses the format $((expression)) o echo $((2 + 2)) o echo $(($((5**2)) * 3))

8 Brace Expansion Allows you to create multiple text strings that follows a certain pattern o echo Front-{A,B,C}-Back o echo Number_{1..5} o echo {Z..A} You may use echo to read environment variables o echo $USER o echo $PATH When using strings, surround them with double quotes

9 Escape Characters Characters such as $, !, & have special meaning To use them you must use escape characters which basically means putting a backslash before the character o echo "The balance for user $USER is: \$5.00"

10 Assignments Check the class OpenLab site for new Labs Check Blackboard for new Quizzes


Download ppt "EMT 2390L Lecture 4 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts."

Similar presentations


Ads by Google