Bash – Create a new file

To create a new file in Bash scripting, you can use touch command. Call the touch command and pass the file name as argument.

The syntax of the expression to create a new file using touch command is given below.

touch path/to/file

The touch command creates an empty file. Yeah a file already exists with the same name, then the modification time for the file is updated to the current time.


In the following script, we create a new file named data.txt, using touch command.


touch data.txt
echo "File created successfully."

Bash Version: GNU bash, version 5.2.15(1)-release (aarch64-apple-darwin22.1.0)


sh-3.2# bash 
File created successfully.
Bash - Create a new file


In this Bash Tutorial, we learned how to create a new file using touch command.