A touch command creates, changes and modifies the timestamps of certain files. However, some beginners do not know the methods of using 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 start!
How to create a new file with Touch Command in Linux
The touch command has different options. Let’s start with the basic syntax you can try in the Linux terminal:
You can create a bash file using the touch command. For the example we write a bash Script i.e. Linuxhint.sh by the following command:
Likewise, you can use the touch command to create a new file in a specific directory. For example, use the following command to create a file in the Documents directory:
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 via the following command:
Sometimes you try to create a file but don’t know if it exists in the system. In this case, use the -c option:
As mentioned earlier, the touch command is not limited to file creation as it includes various options such as:
Options Description -a Changes the file access time. -c Don’t create file if it exists. -d Store the date as a STRING. -m Change the modification time of the file. -h Make changes to a file’s symbolic links instead of a referenced file. -t Save the file in [CCYY]MMDDhhmm instead of the current time. -r Store the time of the file instead of the current time.
Additionally, you can use the following command to learn more about the touch command:
This is about creating a new file using the touch command in Linux. The touch command includes various options to create and modify the files and directories from the terminal. We’ve focused solely on creating files using the touch command in this guide. In addition, we used various examples to create the bash script via the touch command. Many Linux users use the cat command instead of the touch command, but there are some differences between them. We’ve uploaded thousands of guides to our official Linuxhint site, so please check them out.