Ubuntu Linux Create a Text File Using cat Command

Ubuntu Linux Create a Text File Using cat Command

On Ubuntu Linux, you can use the cat command to create a new text file. The cat command is a utility that is used to display the contents of a file or to create a new file by combining the contents of multiple files.

To create a new text file using the cat command, you can use the following syntax:

cat > filename.txt
Source:w‮ww‬.lautturi.com

Replace filename.txt with the desired name of the file. This will open the cat command in interactive mode, allowing you to enter text into the file.

To enter text into the file, type the desired text and press Enter to start a new line. To finish entering text and save the file, press CTRL + D.

For example, to create a file called myfile.txt with the following content:

Hello, world!
This is a test file.

You can run the following command:

cat > myfile.txt
Hello, world!
This is a test file.
CTRL + D

Keep in mind that the cat command will overwrite the file if it already exists. If you want to append the text to the end of an existing file, you can use the >> operator instead of the > operator:

cat >> filename.txt

This will open the cat command in interactive mode, allowing you to enter text into the file and append it to the end of the file.

Created Time:2017-10-30 14:27:25  Author:lautturi