How To Create File In Linux with Different Ways? – POFTUT

How To Create File In Linux with Different Ways?


Sometimes creating a file empty or with a little content can be important. In this post, we will look at how to create a file from the command-line interface. Here are alternative ways to create files.

Touch

The touch command is the first choice for creating an empty file with the current user ownership.

$ touch ex1
Touch
Touch

As we can see the owner of the file is ismail and the group of the file is ismail. The permissions are set according to the umask value which is 664 in this case.

Echo

The echo command is a very useful command to put the string into the standard output. We redirect our output to a file new file will be created.

$ echo "" > ex2
Echo
Echo

We can provide some text data to put into a newly created file.

$ echo "Some data" > ex3

Cat

Cat is a command especially created for concatenate files and print on the standard output.

$ cat > ex4
Cat
Cat

After putting command we should press CTRL+d to exit from input mode.

Leave a Comment