Upload
jewel-baldwin
View
214
Download
1
Embed Size (px)
Citation preview
EMT 2390LLecture 4
Dr. ReyesReference: The Linux Command Line, W.E. Shotts
Outline• Redirection• Pipelines• Patterns• Expansions• Shell Arithmetic• Brace Expansion• Escape Characters
Redirection• stdout – default output stream• To redirect output from stdout use >
o ls -l /usr/bin > ls-output.txto 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 outputo Usage: cat file1 file2 … fileNo cat > lazy_dog.txto cat lazy_dog.txt
• To redirect input use <o cat < lazy_dog.txt
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 | … | commandNo ls -l /usr/bin | less
• sort – sorts the inputo ls /bin /usr/bin | sort | less
• uniq – removes duplicateso ls /bin /usr/bin | sort | uniq | lesso 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
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 fileo head ls-output.txto head -n 5 ls-output.txt
• tail - prints the last 10 lines of a fileo tail ls-output.txto tail -n 5 ls-output.txto 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 fileso ls /usr/bin | tee ls.txto ls /usr/bin | tee ls.txt | grep zip
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 themo echo *o echo D*o echo *so echo ~
Shell Arithmetic• Uses the format $((expression))
o echo $((2 + 2))o echo $(($((5**2)) * 3))
Brace Expansion• Allows you to create multiple text strings that
follows a certain patterno echo Front-{A,B,C}-Backo echo Number_{1..5}o echo {Z..A}
• You may use echo to read environment variableso echo $USERo echo $PATH
• When using strings, surround them with double quotes
Escape Characters• Characters such as $, !, & have special meaning• To use them you must use escape characters
which basically means putting a backslash before the charactero echo "The balance for user $USER is: \$5.00"
Assignments• Check the class OpenLab site for new Labs• Check Blackboard for new Quizzes