Creating Empty Files – touch

  • touch: Creates empty files

A simple and empty text file can be created with the touch command in the terminal. The command structure is as follows:

$ touch file-name1 file_name2 'file name3' FileName4 file\ name\4

Sometimes when working on a project, you need to create some empty files as placeholders which you’ll write contents later. This is the same as using pass in programming languages. It simply creates empty files. But if the file already existed, then touch command does not hurt at all. Every file has metadata about when the file was created or modified last time and some more related information. Touch command just updates this metadata for previously existed files if tried to create again.

Let’s create some files in a new folder from home directory.


Here ls-l is showing the metadata of the files. You’ll learn about this command in detail in a later tutorial.

One very important thing to notice here. All the files were created with different extensions, but if you check your MLwiki folder, you’ll see that all of the files are text files. This is the character of touch command, as mentioned at the beginning. But if you open the files with appropriate software, some of them will be converted to the appropriate file type after saving.

Space in Filename

When creating files from the terminal, you can’t include space in the file name as the terminal uses space to separate multiple commands. Already you’ve seen some alternatives for that. But if you really want to include space in the filename, then either wrap the name with single quotes to make it a raw string, or use backslash as an escape character. Remember, backslash can escape only the immediately following character. So be careful when using a backslash as an escape character.

up2 1

Creating multiple files with touch

You can create multiple files with a single touch command, just the same as you saw in previous tutorials. Just separate the filenames with space, and all the files will be created at once.

Mind Sharing It?
Join Facebook Group

Public Group

A group optimized for learning purposes. Track your progress by joining a unit

Follow on Quora

Public Space

Best place to ask questions! Join the built-in community to get help from others