Linux Commands

How to Create a New File Using Linux Touch Command

Linux contains a ton of useful commands to simplify the tasks. Linux commands can handle everything, whether creating new directories or making changes in the system. You can also generate Bash scripts from the terminal as it only requires the touch command.

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:

touch <option> <file_name or directory_name>

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:

touch Linuxhint.sh

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:

cd ~/Documents
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:

touch Ubuntu.sh Fedora.sh CentOS.sh KaliLinux.sh

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:

touch -c Linuxhint.sh

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:

touch --h

Or

touch --help

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.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.