The Linux operating system has multiple objects, such as application files, directories, system files, and binary files. These objects contain metadata information along with the files, which include create, access, and modification time. Sometimes, you may need to update these timestamps and the Linux touch command is a way to do it.
In this tutorial, we will learn about the touch command line utility in Linux.
Prerequisites
- A Linux computer with terminal access.
- Understanding of Linux command-line interface.
- Excitement to learn new Linux commands.
Linux Touch Command
The Linux touch command is primarily used to modify a file timestamp. It can also be used to create an empty file. When you work on your Linux computer, you may need to create an empty file so that applications can write to it. Also, certain administrative services may require files to have a certain timestamp. The touch command in Linux can do both of these jobs. This command does not change file contents.
Touch can update the access and modification time of the specified file. However, if the specified file does not exist, then touch creates a new file with the specified name. It creates an empty file and you can add data to it later using any text editor. To update access and modification time, the file must exist on your system.
Before we dive deep into this command, let’s understand what three timestamps in Linux are:
- Access time (atime) – The last time when some command or application accessed the file.
- Modify time (mtime) – The last time when the content of the file was modified.
- Change time (ctime) – The last time when any attribute or content of the file was changed. Change time can be updated without updating the content.
Use the stat command in Linux followed by the file name to display the file timestamps.