A touch command creates, changes, and modifies the timestamps of specific files. However, some beginners don’t know the methods to use the touch command to create files from the terminal. Please read this guide if you also want to know how to create a new file using the touch command. Let’s begin!
How to Create a New File Using Touch Command in Linux
The touch command has various options. Let’s start with the basic syntax that you can try in the Linux terminal:
You can create a Bash file using the touch command. For example, let’s write a bash script, i.e. Linuxhint.sh, through the following command:
Similarly, you can use the touch command to make a new file in a particular directory. For example, use the following command to create a file in the Documents directory:
touch Linuxhint.sh
If you want to create multiple files, add the name of the files in the single command. In this example, we can create Ubuntu.sh, Fedora.sh, CentOS.sh, and KaliLInux.sh through the following command:
Sometimes, you try to create a file but you don’t know if it exists in the system. In this case, use the -c option:
As we previously mentioned, the touch command is not limited to file creation as it contains various options such as:
Options | Description |
---|---|
-a | Changes the file access time. |
-c | Do not create a file if it exists. |
-d | Saves the date as a STRING. |
-m | Makes changes in the modification time of the file. |
-h | Makes changes in the symbolic links of a file rather than a referenced file. |
-t | Saves the file in [{CC}YY]MMDDhhmm rather than the current time. |
-r | Saves the file’s time rather than the current time. |
Moreover, you can use the following command to learn more about the touch command:
Or
Conclusion
This is all about creating a new file using the touch command in Linux. The touch command contains different options to create and modify the files and directories from the terminal. We focused this guide solely on creating files using the touch command. Moreover, we used various examples to make the Bash script through the touch command. Many Linux users use the cat command instead of the touch command, but there are a few differences between them. We uploaded thousands of guides on our official Linuxhint website, so please check them out.