How to Use the Touch Command in Ubuntu

How to Use the Touch Command in Ubuntu

The ‘touch‘ command in Ubuntu is a versatile tool for creating empty files and modifying file timestamps. Whether you need to generate a new file or update timestamps for scripting purposes, mastering ‘touch’ is a valuable skill. In this guide, we’ll walk you through the step-by-step process of using the ‘touch’ command in Ubuntu, complete with examples and practical tips.

Advantages of Using Touch Command

Using the touch command in Linux offers several advantages and use cases:

  1. Efficient File Creation. It allows for the quick and effortless creation of empty files, eliminating the need for manual content creation.
  2. Scripting and Automation. It’s a valuable tool in scripting and automation tasks, enabling the creation of placeholder files and timestamp manipulation as part of automated processes.
  3. Dependency Fulfillment. It helps fulfill dependencies, ensuring that specific files exist when required by software or scripts.
  4. Directory Structure Preservation. When copying or moving files, touchcan recreate directory structures and empty directories, helping to maintain the organization of files.
  5. Timestamp Management. You can easily modify file timestamps using ‘touch,’ enabling precise control over access and modification times for various purposes.

Overall, the ‘touch’ command is a simple yet powerful utility in Linux, providing flexibility for a wide range of tasks and scenarios. It serves as a valuable tool for both system administrators and developers alike. In the next section, we’ll delve into how to use it.

Utilizing the Touch Command in Ubuntu

Here’s a step-by-step guide on how to use the “touch” command in Linux, complete with an example and expected output.

#1 Open a Terminal

Launch a terminal window on your Linux system. You can usually do this by pressing or searching for “Terminal” in your application launcher.

#2 Navigate to the Desired Directory

If you want to create the file in a specific directory, navigate to that directory using the cd command. For example:

cd ~/Documents

#3 Use the “touch” Command

o create an empty file, use the “touch” command followed by the desired file name. For example, to create a file named “example.txt,” type:

touch example.txt

#4 Verify the Creation

To verify that the file was created, you can use the “ls” command to list the files in the current directory. For example:


You should see “example.txt” listed among the files in the directory.

Sample Output:

Snapshot of ls command in Linux terminal. Showing example.txt as a result.

#5 Check File Timestamps

You can also use the “stat” command to check the timestamps of the newly created file. For example:

stat example.txt

This will display information about the file, including its timestamps.

Sample Output:

Snapshot of "stat" command for example.txt. Showing information including its timestamps.

Example: Suppose you want to create an empty file named “important_notes.txt” in your “Documents” directory.

cd ~/Documents
touch important_notes.txt

This confirms the successful creation of the “important_notes.txt” file in your “Documents” directory.

That’s it! You’ve successfully used the “touch” command to create an empty file in Linux. You can use this command to quickly generate empty files for various purposes.


Want to run Ubuntu in a virtual environment? With Gcore Cloud, you can choose from Basic VM, Virtual Instances, or VPS/VDS suitable for Ubuntu:

Choose an instance

Subscribe to our newsletter

Stay informed about the latest updates, news, and insights.