I/O Redirection in Linux

In this blog we will learn how we can use redirection in Linux .Redirection simply means capturing output from a file command or program and sending it as an input to another file command or program .

1.We are going to use the cat command to create a file and then transferring our stream to this file .The command look like this cat > filename .Here > means we want to redirect our input or whatever output we are going to type in the terminal to a file .

Now you again repeat the command and type some content it will actually overwrite the previous content.

2.Now we want to append to the file ,previous content of the file should not be overwritten but it should be whatever we want to add to a file it will be added from the next line so what we do in that case we give the same command with two angle brackets so this is for appending to the existing content of a file .Command : cat >> filename

3.Sometimes we want to add two files and then transfer the content to the new file .To do this what you can do is : cat file1 file2 > new file . Now the new file will have the content of file1 and file2 .

 In this wayyou can use a redirection in Linux . Redirection is particularly not related to the cat command you can do the samething with for example ls also . Example : ls -al > filename . Now the file will have output of ls command .

This is all about redirection in linux.

Partner Sites




Be the first to comment

Leave a Reply

Your email address will not be published.