How to create a file in Linux via terminal - touch command
- Last updated: Nov 3, 2023
- Views: 229
- Author: Admin
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.