how to redirect using cat command in linux | Pro Tech guides

how to redirect using cat command in linux

You can use linux cat command allows redirect files. To create files, concatenate files, add files. display files and more.

How to redirect using cat command in linux | unix | with examples

Redirection using cat command
redirection using cat command

Hello, guys Today I'm going to show you how you can use "Redirection in Linux"

what is redirection?

Redirection simply means capturing output from a file command or program and sending it as an input to another file command or program.

And let's see what are the options we have for the redirection. So, For example, you want to transfer some output 

Output > file

So I will just write output here and then you want to redirect it to a file. So, in this case, we want to send some output to a file and the arrow (>) indicates the direction of your output. So you want to send the output to the file this arrow (>) means the direction of your output.


Create a file using cat command

So let's see how we can use it so in the last session I've shown you how we can use the cat command in Linux. So we are going to use this cat command to create a file and then transferring our stream to this file. Just say cat here and then this (>) angle bracket this means we want to redirect our input or whatever output we are going to type in the terminal to a file. And let's name a file For example "test.txt"  and when I press ENTER.


linux cat command add text
linux cat command create a file
$cat > file name

linux cat command add text
file


Here you will see there is a new file created right as soon as you press Enter. Now whatever you write here then this content will be written to the file. after finished your content you just need to press "ctrl + D" to indicate that this is the end of your file and then you are out of this cat command. 

linux cat command print output
linux cat command print output
$cat file name

Let's see what's the content of this test file. So I can just cat this test file here so just press ENTER and you can see the content of this "test.txt" file.

Overwrite the content of the file

overwrite a file using cat command
overwrite a file using cat command
$cat > file name

What I want to do is I want to once again transfer something else to this "test.txt" file so once again I will just do cat with this angle bracket (>) and then the filename and then this time I want to add some content then I will just press Ctrl + D and now you will see that this "test.txt" file contains new content and earlier whatever content we have written to the file is overwritten by the new content.


Append the content of the file

linux command cat append
linux command cat append
$cat >>file name


You want to append to the file. you want that this file should not be overwritten but it should be whatever you want to add to a file it will be added from the next line.

For example, 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. When you give two angle brackets (>>) and press Enter.


Concatenate two or more files

cat command to concatenate
cat command to concatenate
$cat file1 file2 > output file


Sometimes you want to add two files and then transfer the content to the new file. I have these two files "list1.txt" and "list2.txt" For example I want to add the content of these two files and transfer it to a new file so what I can do is I can just write "cat list1.txt list2.txt > output.txt"

So this is the command so I want to join these two files and then transfer the content of the concatenation of these two files to our new file. When I press ENTER the new file will be created.

When I see the content of this "output.txt" file. I can see the combination of our two files. In this way, you can add any number of file.

Conclusion

In this way, you can use redirection in Linux. So it's not particularly related to the "cat command" you can do the same thing with For example I will just write "ls -l > out.txt" and press Enter and when I see the content of out.txt then it gives me the output of ls command.

So it's not particularly related to cat command you can use this redirection to any other command or program.

So I hope you enjoyed this tutorial please rate comment and bye for now.

HAVE A NICE DAY
 See also,

Name

Apps,3,Games,1,Linux,38,Linux Commands,37,Network-Devices,1,Networking,1,Terminal Apps,2,Termux,17,Userland,3,Windows,1,
ltr
item
Pro Tech guides: how to redirect using cat command in linux
how to redirect using cat command in linux
You can use linux cat command allows redirect files. To create files, concatenate files, add files. display files and more.
https://1.bp.blogspot.com/-S7sPA46sFKQ/X7qGByei0tI/AAAAAAAACac/X6rGP7jnTH84i4_nOlMJMFbMnQz1qJyGACNcBGAsYHQ/s16000/redirection%2Busing%2Bcat%2Bcommand.png
https://1.bp.blogspot.com/-S7sPA46sFKQ/X7qGByei0tI/AAAAAAAACac/X6rGP7jnTH84i4_nOlMJMFbMnQz1qJyGACNcBGAsYHQ/s72-c/redirection%2Busing%2Bcat%2Bcommand.png
Pro Tech guides
http://www.protechguidez.com/2020/11/how-to-redirect-using-cat-command-in-linux.html
http://www.protechguidez.com/
http://www.protechguidez.com/
http://www.protechguidez.com/2020/11/how-to-redirect-using-cat-command-in-linux.html
true
7053638852026728047
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content