IO Redirection

Other topics

Output Redirection

Usually output of a command goes to the terminal. Using the concept of Output redirection, the output of a command can be redirected to a file. So insted of displaying the output to the terminal it can be send to a file. '>' character is used for output redirection.

$ pwd > file1
$ cat file1
/home/cg/root

In the above example, the command the output 'pwd' of the command is redirected to a file called 'file1'.

Input Redirection

The commands normally take their input from the standard input device keyboard. Using Input redirection concept, we can have their input redirected from a file. To redirect standard input from a file instead of the keyboard, the '<' character is used.

$ cat file1 
monday
tuesday
wednsday
thursday
friday
saturday
sunday

The above is the content of file1

$ sort < file1
friday
monday
saturday
sunday
thursday
tuesday
wednsday

here insted of taking input from keyboard, we redirected it from the file1 and sort it in ascending order.

Syntax:

  • [fd]<file
  • [fd]<&fd
  • [fd]<&-
  • [fd]>file
  • [fd]>&fd
  • [fd]>&-
  • [fd]>|file
  • [fd]>>file
  • [fd]<>file
  • [fd]<<[-] word
    ...
    word

Contributors

Topic Id: 9345

Example Ids: 28941,28942

This site is not affiliated with any of the contributors.