Command to create new file in linux

In Linux, you can create a new file using the following commands:

  1. touch command:

    touch filename.txt

    This will create a new empty file named filename.txt.

  2. echo command:

    echo "Hello World" > filename.txt

    This will create a new file named filename.txt and write the text "Hello World" to it.

  3. cat command:

    cat > filename.txt

    This will create a new file named filename.txt and allow you to type text into it. Press Ctrl+D to save and exit.

  4. nano editor:

    nano filename.txt

    This will open the nano editor and allow you to create a new file named filename.txt. You can type text into it and save it by pressing Ctrl+X, then Y, then Enter.

  5. vim editor:

    vim filename.txt

    This will open the vim editor and allow you to create a new file named filename.txt. You can type text into it and save it by pressing Esc, then :wq, then Enter.

Note: Replace filename.txt with the desired name of your new file.