How to Create File in Linux

In this lesson we will see how to create files in Linux system.

Create a file in Linux:

a. Create file using touch command:

$ touch info.yaml

Create multiple files using touch command:

$ touch info.yaml data.txt mail.tmp

b. Create file using Redirection operator:

$ > info.yaml

c. Create file with echo command

$ echo "Hello World" > info.yaml
# to create an empty file
$ echo > map.yaml

d. Create file using cat command:

# create the infoTemp.yaml file and redirect the content of the info.yaml to it
$ cat info.yaml > infoTemp.yaml

e. Create file using Heredoc: Heredoc allow us to redirect multiple lines to a file

$ cat << EOF > info.yaml

This is the first line
This is the second line

This is the third line


Also see file manipulation and how to Find file in Linux . See complete examples in our GitHub repository.

Follow us on social media