A Guide to the Touch Command in Linux

04 May 2023 Balmiki Mandal 0 Linux

Introduction to Touch Command in Linux

The touch command is one of the most versatile commands used in the Linux operating system. It is used to create, modify and update the access and modification time of a file or directory. Touch command is part of the GNU Coreutils package that comes pre-installed in most Linux distributions. This guide will explain how to use the touch command in Linux.

How to Use Touch Command in Linux

Touch command accepts options along with file or directory names as arguments. Let's go through some examples of the most common uses of the touch command.

Create a file: To create a new empty file using the touch command, simply type “touch filename.extension”, replacing filename and extension with preferred name and type respectively. For example, to create an HTML file, type “touch myfile.html”.

Modify timestamp: Touch can be used to modify the timestamp of an existing file or directory. To do this, type “touch -t YYYYMMDDHHMM filename.extension”, replacing the values after -t with the Year (YYYY), Month (MM), Date (DD), Hours (HH) and Minutes (MM).

Update access and modification times: To update the access and modification times of a file or directory, type “touch -a filename.extension” or “touch -m filename.extension”. This will update the Access ( -a ) or Modification ( -m ) times of the file.

Conclusion

The touch command is a powerful and useful tool for managing files and directories in the Linux operating system. It can be used to create, modify, and update the access and modification times of a file or directory. This guide explained how to use the touch command in Linux and presented common use cases.

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.