Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS 240 Introduction to UNIX Instructor: Sue Sampson.

Similar presentations


Presentation on theme: "CIS 240 Introduction to UNIX Instructor: Sue Sampson."— Presentation transcript:

1 CIS 240 Introduction to UNIX Instructor: Sue Sampson

2 CIS240 – UNIX File Redirection Standard Files Standard files are opened by the kernel for every command that gets executed There are three:  stdin Used for input  stdoutUsed for output  stderrUsed for error messages

3 CIS240 – UNIX File Redirection Default Associations If another file is not specified in the command line, the kernel assigns these files as follows:  stdinkeyboard  stdoutdisplay screen  stderrdisplay screen

4 CIS240 – UNIX File Redirection Remember -- the UNIX file system supports: - Simple/ordinary files - Directories - Symbolic (soft) links - Special files (devices) - Named pipes (FIFO) - Hard links

5 CIS240 – UNIX File Redirection When Executing Commands We can re-direct the input to a command from any Unix file We can re-direct the output from a command to any Unix file We can re-direct error messages from a command to any Unix file

6 CIS240 – UNIX File Redirection Redirection (0=input, 1=output, 2=error out) Input Syntax:  command < input-file sort < tempfile.dat (sort will get its input from tempfile.dat instead of the keyboard) Output Syntax  command > output-file ls –al > directory.txt (The output from the ls command would go to directory.txt instead of the display screen) Error Syntax  command 2> error-file ifup eth0 2> error.log (The error messages generated by the ifup command would be sent to a file called error.log)

7 CIS240 – UNIX File Redirection Piping Piping takes the stdout from one command and makes it the stdin for another – filtering as you proceed.  Syntax: command1|command2|…|commandn grep Sampson class.txt | sort +3 (Look for lines that contain Sampson in the class.txt file – that becomes input for the sort command, which sorts the results on the 4 th column, and outputs to the standard out.) Add redirection… grep Sampson class.txt | sort +3 >sortedclass.txt (Look for lines that contain Sampson in the class.txt file – that becomes input for the sort command, which sorts the results on the 4 th column, and outputs to the sortedclass.txt)

8 CIS240 – UNIX File Redirection tee Utility Combines redirection and piping – when you want the input of subsequent commands to be the output files of previous commands.  Syntax: command1|tee file1…filen|command2 cat names | grep “Sampson” | tee file1.txt wc -1 (Look for lines that contain Sampson in the names file – send the results to file1.txt, which becomes input for the wc command, the end result sends the resulting line count to the monitor.)


Download ppt "CIS 240 Introduction to UNIX Instructor: Sue Sampson."

Similar presentations


Ads by Google