The best way to create files on Linux

The best way to create files on Linux

Create files on Linux

There are various ways to create files on Linux. You can create and edit files using various commands from the terminal. In this tutorial, you will learn the best way to create files on Linux.

1. Create a file using the touch command

You can create a file using touch command. To create a file using touch Commands are executed under commands. Create demo.txt Files in current directory:

touch demo.txt

Execute the following command to check the created file.

ls -l

The output looks like this:

-rw-r--r--. 1 root root       0 Apr  11 21:12 demo.txt

2. Create a file using the nano command

You can create a file using nano command. To create a file using nano Commands are executed under commands. Create demo2.txt Files in current directory:

nano demo2.txt

Write something in the file and press Ctrl+x That y Save the file.

Execute the following command to check the created file.

ls -l

The output looks like this:

-rw-r--r--. 1 root root       0 Apr  11 21:16 demo2.txt

3. Use the echo command

You can create a file using echo command. To create a file using echo Commands are executed under commands. Create demo3.txt Files in current directory:

echo "Hello World" > demo3.txt

Execute the following command to check the created file and check the contents of the file.

cat demo3.txt

The output looks like this:

Hello World

4. Create file on Linux using vi command

You can create a file using vi command. To create a file using vi Commands are executed under commands. Create demo4.txt Files in current directory:

vi demo4.txt

Write something in the file and press esc(Escape key) then :wq Save the file.

Execute the following command to check the created file and check the contents of the file.

cat demo4.txt

The output looks like this:

Hello World

5. Use printf command

You can create a file using printf command. To create a file using printf Commands are executed under commands. Create demo5.txt Files in current directory:

printf "Hello World" > demo5.txt

Execute the following command to confirm creation of the file and confirm the contents of the file.

cat demo5.txt

The output looks like this:

Hello World

Conclusion

In this tutorial, you learned the best way to create files on Linux. If you have any questions about this, you can comment below.

Sidebar