Digital Communication


Digital Communication

Linux touch: change timestamp and create files


The Linux touch command was designed for manually changing modification and access times, but it is often primarily used for creating new files. Using the options, specify whether to take into account the system time or an individual timestamp.

Linux touch command: what is it?

The Linux touch command is used to change timestamps related to modification and access to individual files or directories. As a file is created automatically if it does not already exist, this command is also very often used to create new empty files. This normally secondary use is of much more importance to most users' daily command line work. The Linux touch command is supported by all major Linux distributions, such as Debian or Ubuntu; it is also pre-installed there.

How does the touch command work?

The Linux touch command is mainly used to change the timestamp. To do this, simply call the corresponding file with the command and add the desired time there. The system then changes the timestamp accordingly. No time is indicated? If so, the command uses the current system time. In the same way, the command creates the file in question if it does not yet exist, unless an option prohibits it. The touch command is therefore the simplest solution for creating new empty files.

What does the touch command syntax look like?

The syntax of the Linux touch command is as follows:

$ touch [Option] [Fichier]


If you use the command without any options, it will modify the timestamp of the file concerned so that it matches the system time, or else recreate the file. Do you want to set the timestamp yourself? Do not hesitate to use the different options available to you.

What options does Linux touch offer?

Below are options available for the touch command:

  • -has : This option only allows you to customize the access time.
  • -c or –no-create: this is used to prevent the creation of a new file.
  • -d or –date=STRING: This command uses the specified timestamp instead of the system time.
  • -m: This option only allows you to customize the modification time.
  • -r or –reference=FILE: this uses the timestamp of the reference file provided.
  • -t TIMESTAMP: This command allows you to use a manual timestamp, specified in the format [AA]MMDDhhmm[.ss].

Touch command: examples

Learn the different ways you can use the Linux touch command with these practical examples:

This command applies the current timestamp to the file example.txtor recreates the file.

$ touch -t 2301011536 exemple.txt


This command allows you to define the timestamp of the file example.txt to January 1, 2023 at 3:36 p.m.

Télécharger notre livre blanc

Comment construire une stratégie de marketing digital ?

Le guide indispensable pour promouvoir votre marque en ligne

En savoir plus

Souhaitez vous Booster votre Business?

écrivez-nous et restez en contact