Touch Command in Linux with Examples

Touch command is used in Linux, Ubuntu operating system to create empty files, changing or modifying the timestamp of existing files and directories.

In Linux OS every file has last access and modification time. You can check this through stat command or ll command.

stat command shows the complete timestamp of a file. It shows the last access,modify and change timestamp.

Linux Commands with Examples.

So whenever we create or modify an existing file it’s timestamp automatically updated.

Touch Command with Examples in Linux

Touch command is used to create empty files, modify access time of files and directories.

Before we begin let’s check some options with touch command.

Subscribe Our Tutorials

Get Latest Updates on Facebook

-a – Change the access time.
-c – If the file does not exist, do not create it
-d – Update the access and modification times
-m – Change the modification time only
-r – Use the access and modification times of file
-t – Create a file using a specified time

Creating an Empty File through touch Command

Use -c with touch command if you don’t want to create new file if it doesn’t exist.

VI/VIM Editor .

Create multiple files using touch command.

Change Access and Modification Timestamp of a File using touch command

You can use -a switch with touch command to change the timestamp of a file.

This file is already created by using touch -a with filename access time of this file is updated to the current time.

Change Last Modification time with Touch Command

Copy the Timestamp of Another File

You can also update the timestamp of another file using -r switch with touch command.


About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , . Bookmark the permalink.