Skip to main content

Module 1: File & Directory Management

Lesson 10: touch Command

In this lesson, you'll learn how to use the touch command to create, change, and modify the timestamps of a file in Linux.

The touch command is a standard program for Unix/Linux operating systems that is used to create, change, and modify the timestamps of a file.

Let's now discuss some options offered by the touch command, and then we will explore different touch command examples.

touch Command Syntax

touch [OPTIONS] FILE

touch Command Options

Option Description
-a Change the access time only
-c If the file does not exist, do not create it
-d Update the access and modification times
-m Change the modification time only
-r Use the access and modification times of the file
-t Creates a file using a specified time

1. Create an Empty File

The following touch command creates an empty new file called sheena.

# touch sheena
# ls -l sheena
-rw-r--r-- 1 root root 0 Nov  5 10:20 sheena

2. Create Multiple Files

By using the touch command, you can also create more than one single file. For example, the following command will create 3 files named sheena, meena, and leena.

# touch sheena meena leena
# ls -l
-rw-r--r-- 1 root root 0 Nov  5 10:20 leena
-rw-r--r-- 1 root root 0 Nov  5 10:20 meena
-rw-r--r-- 1 root root 0 Nov  5 10:20 sheena

3. Change File Access and Modification Time

To change or update the last access and modification times of a file called leena, use the -a option as follows.

The following command sets the current time and date in a file. If the leena file does not exist, it will create a new empty file with that name.

# touch -a leena
# ls -l leena
-rw-r--r-- 1 root root 0 Nov  5 11:45 leena

The most popular Linux commands, such as the find command and ls command use timestamps for listing and finding files.

4. Avoid Creating New Files

Pro TecMint Β· Root Plan
This Article is for Root Members
Join Root to read the full article and unlock everything

Full Access to Every Article, Course & Certification Track

Join thousands of Linux professionals who use Pro TecMint to advance their careers.

Ad-free access to all premium articles
All courses: Learn Linux, Bash, Golang, Ubuntu and more
RHCSA, RHCE, LFCS & LFCA certification prep
New courses added every month
Private Telegram community & priority support
Root Plan
$8/mo
or $59/year billed annually
Save $37 with annual plan
Start Reading This Article in the Next 60 Seconds
Join Root Plan β†’