cat command
cat command
-----------
1. How to Create a file and add content in Linux Using `cat` Command
If you want to create a new file or overwrite an existing file with new content,
you can use ‘cat’ with the output redirection (`>`):
Syntax:
cat > newfile_name
Example: If we want to create a newfile_name = vishal.txt
cat > vishal.txt
Hi Team,
Good Morning
ctrl+d
This will allow you to type text directly into the terminal, and when you press
Ctrl + D, the entered text will be saved to vishal.txt.
`ls` command is used to display all files and directories in the current location.
-------------------------------------------------------------------------------
output->
Hi Team,
Good Morning
-----------------------------------------------------------------------------------
----
Output->
1 Hi Team,
2 Good Morning
-----------------------------------------------------------------------------------
------------
6. How to Append the Contents of One File to the End of Another File
If you want to add the content of one file to another, ‘cat’ can be used along with
the append (>>) operator:
Syntax:
cat file_name1 >> file_name2
Example:
cat file1 >> file2
This will append the content of `file1` to the end of `file2`
-----------------------------------------------------------------------------------
---------------------
This will append the text “The newly added text.” to the end of the ‘vishal.txt’
file.
Output->
Hi Team,
Good Morning
The newly added text.
===================================================================================
==================================================================