How to create a file in Linux via terminal - touch command

  • Last update: Apr 3, 2024
  • Views: 39
  • Author: Admin
How to create a file in Linux via terminal - touch command

Hello colleagues.

In today's article, we will talk about how you can create files in Linux using the touch console command .  The Linux touch command is used to create new files or to update the access and modification times of existing files.

 

The syntax for the touch command is:

touch [option] [file name or path to file]

When using the command, parameters are not required.


 

The main parameters of the touch command are:

  • -a -- Change file access time without changing modification time
  • -c -- Don't create a new file if it doesn't exist
  • -m -- Change file modification time without changing access time
  • -r -- Set access and modification times for a file based on another file
  • -t -- Sets the access and modification time for the file at the given point in time in the format YYYYMMDDHHMM.SS

 

Simple examples of using the touch command.

Example 1: Creating a new file.

$. touch it-inzhener.txt

 

Example 2: Change file access and modification time:

$. touch -m it-inzhener.txt

 

Example 3: Set file access and modification time based on another file:

$. touch -r it-inzhener-new.txt it-inzhener.txt

 

Example 4: Set file access and modification time to a given point in time:

$. touch -t 202302011200.00 it-inzhener.txt


 

Thank you all, I hope my article was of some help to you.

SIMILAR ARTICLES

Linux cp command, copying files
How to clear a file in Linux