CSE 391
Shell Commands
More Redirection
Slides created by Josh Ervin and Hunter Schafer. �Based off slides made by Marty Stepp, Jessica Miller, Ruth Anderson, Brett Wortzman, and Zorah Fung
AGENDA
ADMINISTRIVIA
DISCUSSION QUESTION #1
Question 1: Suppose we have a file directories.txt where each line contains the name of a directory that we want to create.
Our friend proposes that we run cat directories.txt | mkdir into order to do this?
Will this command work? If not, how can we change this command to get it to work/could we improve it in any way?
PRIMING SOME QUESTIONS
Questions you may have from pre-lecture:
Questions you may have from homework/last week:
DISCUSSION QUESTION #2
Question 7: Suppose we know that Compile.java compiles with no errors. If we were to run javac Compile.java || java Compile what would be the result? Would the program compile? Would it run?
DISCUSSION QUESTION #8
Question 8: What would be some security issues with running some of the commands you learned from lecture (think of some of the practical implications of rm, find, and xargs in regards to malicious code injection)?
TIPS FOR HW3
AGENDA
ROADMAP
PIPES
command1 | command2
command1 > filename
command2 < filename
rm filename
COMBINING COMMANDS
command1 ; command2
command1 && command2
command1 || command2
What would happen after running the following command: ls *.java | javac
Solution: This won’t work because javac does not read from stdin! Piping makes the stdout of the last program become stdin of the next.
XARGS
FIND
COMMAND SUBSTITUTION
$(command)
What is the command to remove all files listed in the file toRemove.txt?
toRemove.txt
CompilerErrors.java
beans.txt
xargs rm < toRemove.txt
STDERR REDIRECTION
TEE
Suppose we want to run the Java program Mystery. What would be the command to output both standard error and standard output to mystery_out.txt and print both to the console?
java Mystery.java 2>&1 | tee mystery.txt
CUT
cut -d<DELIMITER> -f<FIELD>
LOGS
$ tail -f /cse/web/courses/logs/common_log | grep “391”