In order to create a file in Linux, we have several ways out of which the following are important:
touch command:To create a new empty zero-length file we simply run the touch command followed by the name of file we want to create:
Example:
$ touch file1.txt
To create multiple files at once, we specify the file names separated by space:
Example:
$ touch file1.txt file2.txt file3.txt
Redirection Operator:To create an empty zero-length file, we simply specify the name of the file we want to create after the redirection operator:
Example:
$ > file1.txt
cat Command:To create a new file we run the cat command followed by the redirection operator > and the name of the file we want to create. We press Enter, type the text and once we are done, we press the CRTL+D to save the files:
Example:
$ cat > file1.txt
echo Command:To create a new file we run the echo command followed by the text we want to print and we use the redirection operator > to write the output to the file we want to create.:
Example:
$ echo "Some line" > file1.txt