touch Linux Command
touch Linux Command
In this tutorial, we will learn about the touch Linux command. The touch command is used mainly to create, change, and modify file timestamps. It’s a simple yet powerful command that serves various purposes, such as creating empty files or updating the timestamps of existing files.
touch command
touch Linux command is used to create and modify timestamps of a file on Linux systems. This command creates an empty file.
To know more about the command line switches of the command, issue the man command in the Terminal.
$ man touch
touch Command Examples
This command is often used in shell scripts to create files and modify the file’s timestamps.
$ touch sample.txt
This command creates an empty file named sample.txt in the present working directory. If the file already exists, touch updates its access and modification timestamps to the current time. You can also specify the file path in the command.
Create Multiple Files
You use the command to create multiple files:
$ touch sample1.txt sample2.txt
This creates empty files named sample1.txt and sample2.txt in the current directory.
Exercise
Use the touch command to create a file called readme.
Command flags/options
The command also supports multiple options.
-a option
$ touch -a <filename>
The -a option updates only the access time of the specified file without changing its modification time.
-m option
$ touch -m <filename>
The -m option updates only the modification time of the specified file without changing its access time.
-t option
$ touch -t [[CC]YY]MMDDhhmm[.ss] filename
The -t option allows you to set a specific timestamp. For example, to set the timestamp to 3:45 PM on September 2, 2017
$ touch -t 201709021545 sample.txt
Linux Tutorials
Linux Basic Commands Tutorial page:
More Information on Ubuntu Linux: