Linux is all about commands. A command is technically the name of the program to run in linux. Each and every command has its own intention and job to do. In this tutorial, we’re going to go over one command that we like to think is pretty useful, and it’s the touch command.

The touch command is one of the most commonly used commands in linux and its primary function is to alter the timestamps of the directory or files. A timestamp is referred to as the access time, basically. The touch command is commonly used for the creation of files and directories, but its original purpose is to modify timestamps. Every file or directory contains data, and it’s crucial to know the date of creation, modification, etc.

Let’s look at a few useful examples of the touch command!

The touch command has the following options. These can be found by running: touch –help on a Linux server.

1. To create a file in Linux

You need to run this command to create an empty file.

2. To change access time of files.

Use option -a along with command to alter access time. This command will update the access time to current time. If there is no racknerd.txt file, it will be created.

3. To create multiple files and directories.

The touch command is also commonly used by server admin’s and users to create multiple files and directories, such as the below command example:

4. To change file modification time.

The option -m will alter modification time of a file:

5. To set timestamp of another file

The -r option will set the timestamp of another file.

6. To set access and modification time.

The options will be -c -t to set it.

The above command will set the specific access time on the file racknerd.txt. Once done, just verify using the ls -la command:

These are some of the practical examples of touch command. We hope that you found this tutorial helpful. If you are looking for a new Linux server host (such as a VPS or dedicated server), be sure to take a look at some of RackNerd’s server hosting solutions below.

Server Hosting Solutions by RackNerd:

Shared Hosting
cPanel Web Hosting in US, Europe, and Asia datacenters
Logo
Reseller Hosting
Create your new income stream today with a reseller account
Logo
VPS (Virtual Private Server)
Fast and Affordable VPS services - Instantly Deployed
Logo
Dedicated Servers
Bare-metal servers, ideal for the performance-demanding use case.
Logo

Leave a comment

Your email address will not be published.