 redirection and pipes in Linux. So these are the learning outcomes. At the end of this session, students will be able to explain redirection and pipes in Linux. So we'll now move to the next slide that is on the redirection. So first we'll understand what is redirection. Redirection is a feature in Linux such that when executing the command you can change the standard input output devices. The basic workflow of any Linux command is that it takes an input and gives an output. The standard input that is stdin that is the device is the keyboard and the standard output that is the device is the screen. With redirection the above standard input and output can be changed here. So the output direction for the symbol is used that is the greater than sign. So the greater than sign the symbol is used for the output that is stdin redirection and for the input redirection the less than sign the symbol is used for the input that is stdin redirection. Next we'll see the file desiccators that is fd. In Linux the every file has the number called fd. If you execute any command or the program in Linux there are three files are always open they are that is the standard in standard out and the standard error. For that the file numbers are given that is the file number is zero for the standard in for the standard output it is one and the standard error is the two. So in Linux or Unix the everything is a file that is the regular file directories or even the devices are files. Every file has an associate number called as a file desiccators your screen also has an file desiccator when a program is executed the output is sent to the file desiccators on the screen and you see the program output on the monitor. If the output is sent to the file desiccators of the printer the program output would have been printed. So these are known as an file desiccators. So now we'll see one more feature that is an that is the error redirection. So when whenever you execute the program or the command at the terminal the three files are always open that is standard input standard output and the standard error. So these files are always represent whenever the program is run as explained before the file desiccator is associated with each of this file. So as we have seen in the previous slide that is standard input zero file desiccator is associated for standard output it is one and the standard error that is sd err that is two. So by default the error stream is displayed on the screen and the error redirection is routing to the errors to the file other than the screen. So while searching for the files the one typical leak gets the permission denied errors. These errors usually do not help the person searching a particular file. So while executing the shell creep you often do not want an error message to be displayed on the program outcome. The solution is to redirect the error message to the file. So next we are going to see what are the pipes in linux the symbol a pipe donates the pipe if you want to use the pipe command in the linux we have to use this symbol that is a straight line that is the pipe and the pipes are used to run the two commands consecutively and it helps in the powerful command for making the powerful command in the linux. So we will see in detail the pipe is the command in the linux that lets you to use two or the more commands such that the output of one command serves as the input to the next. In short the output of each process is directly as inputted to the next one like a pipeline the symbol a straight line that donates the pipe. The pipe helps you smash up the two or more commands at the same time and run them consecutively. You can use more powerful commands which can be performed the complex task in a second. Next if you want to use one more consecutively command with the pipe so that is one more that is the grape command. So what does the grape commands does? It sorts the documents so that's why it is known as the sorting command also that is it scans the documents. If you want to use the grape command you have to use the following command that is present the result in the format you want that is grape and they search for the string in the file. So all these redirection the file descriptors pipe and the grape commands we are demonstrated using the linux terminal. So suppose if you want to search a particular file information the postal code from the text file you may manually see the content yourself to the trace the information. A better option is to use the grape command it will scan the document for the desired information and present the result in the format you want. Means it is like an sorting. So now whatever we have seen so we have to do an demonstration using an linux. So I will be switching over to the terminal. So what we have seen the previous videos. So now we'll see the output redirection how it has been used. So for using an output redirection we have to make use of an greater sign here. So now we'll see how many files are there on the desktop here. So for that we are going to make use of an LS command. So there is only one file. If you want to get the details of this file so we have to make use of an command LS minus AL. So you will get all the details of this file here that is this is the directory read write access and all this root who is the permission who is the owner and all this thing here. Now suppose I if you want to make use of an output direction whatever the output is going to be there that file has to be in create here. So for creating the file we have seen touch output. So that file will be created if you want to see you can see now that is file as well as the output file will be there. Now whatever the commands we are going to see LS minus AL greater than the output will be printed into that file that is an output. So if we do the cat using if you want to see the things inside the output file we can see by using the cat command. So whatever the things are there detail so it has been outputted on the output file here in the same manner if you want to append the new things whatever you have done here. Now suppose if you want to add eco you have to make use of an double this eco ICT into the same file that is an output. So it will be appended in the same manner here. Now if you see that command that is cat LS minus AL cat output. So if you have seen these are the two files here. So use the correct file name while the redirecting the command output to the file. If there is an existing file with the same name the redirected command will delete the content of that file and then it may be an overwritten. If you don't want to file to be overwritten but if you want to add more contents into an existing file then it should be double greater than sign operator should be used here. Next we will see the input direction here. So input direction is nothing but we have to make use of an the less than sign here. Now suppose if you are going to make use of an mail suppose if you are going to mail this the subject name is good morning to address and the file name whatever the file you are going to attach that will be then input to the mail. So now suppose the file is not see here if you run this command you will be inputted to that mail here and the mail will be sent to that email address here. But now the file mail server is not installed here. So that's why if you run this command so it will be not say it will not be send here because the mail command is not found here. So before trying to this install mail utility then you will be able to run this command here. Next we will see the summary of redirection. Each file in the Linux has an corresponding file dc separators associated with it. The keyboard is a standard input device which your screen is the standard output device. A greater than is the output redirection operator and double greater than in signs are used it will happen output to an existing file. So next if you see the less than it is an input redirection operator here. So you can redirect the error using an corresponding file that is dc separator 2. So now we will see the examples of a pipe and the grape here. Now suppose if you done a cat an output file. So you have seen all this data here. Now suppose if you want to see the less data you can see you can make use of an cat make use of an pipe make use of an pipe here output pipe less. So the less data will be shown here if it is more than you can have. Now suppose if you want to quit this you have to make use of an queue here. So in this way you are going to make use of an pipe. So instead of less you can also use the cat the output file name and pipe PG or the cat file name or more if the more contents are to be displayed here. Now suppose if you are going to make use of an the grape command here. So for that we will add some file data to the some file here. So before that we have to create one file touch file one. So touch file is created. So in that we are going to make use of an nano command. So we will write cat dog apple 8. So these are the four things I have kept here enter. So if you see the file so you'll see cat dog apple and eat here now. So using the grape command if you want to search for an apple. So we are going to do that. So cat file name pipe grape command and apple. So it will search for the apple here in the same manner if you want to search for a dog. So you can search for the dog it will search the particular data inside the file here. So there are many more commands you can make use of the grape command. Suppose if you are going to make use of an the minus V. So it shows all the lines that do not match the search string in the same manner if you are going to do with minus I just show the name of the file using the string here. So let us try with the one example that is option minus I on the same file what we have done here. So using this command so we have cat file name grape minus I a so whatever the a is there so it will be shown. So cat has a apple has an a it has an a so for particular whatever the string we want to search you can string using the grape I command in the same manner there are minus C minus N and minus L commands are used using the grape command here. So this was the demonstration for the pipes grape commands used here now. So this was then grape command here. So now just recall how many files are used for representing the different standard stream. So the answer is three that is input output and the error file that is the standard input standard output and standard error here. So these are my references. Thank you.