Creating a file in Linux

We can create a file in Linux in many ways.

  1. cat > myfile.txt : This command will accept the data from standard input and put it in “myfile.txt”. Note that you will have to press the ctrl+c hot key to mark the end of input.
  2. touch “myfile” : This command will create file if it does not exist.
  3. printf “This will go in file ” > “myfile”
  4. echo “This will go in file ” > “myfile”
  5. You can create a file using output redirection operator ( > ). Output of any command is sent to new file.
  6. nano/vi – You can also use any of the editors to create a new file

You may also like...