You are currently viewing Linux Commands – touch

Linux Commands – touch

  • Post author:
  • Post category:Linux

Linux Commands – touch

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed tail command in Linux which is used to print some lines from the bottom of a file or pipe.

https://cloudaffaire.com/linux-commands-tail/

In this blog post, we will discuss touch command in Linux. the touch command is used to update the access and modification times of a file to the current time. If the file does not exist, touch will create an empty file. Every file in Linux has some timestamp associated with it. There is mainly three types of timestamp available to track the last access time (atime), last modify time (mtime), and last change time (ctime). Using touch command, you can change the file atime and mtime.

  • access time (atime): access time tells when the file’s content was last accessed.
  • modify time (mtime): modify time tells when the file’s content was last changed.
  • change time (ctime): change time tells when the file’s attribute (metadata) was last changed.

Linux Commands – touch:

You can use the touch command to change the file access time and modify time. If the file does not exist, the touch command will create an empty file with the current timestamp.

You can use touch -a or –time=[atime|access|use] options to change only the access time of a file.

You can use touch -m or –time=[mtime|modify] options to change only the modification time of a file.

You can use touch -c or –no-create options to not warn about or create files that do not exist. By default, touch command creates an empty file with the current timestamp if the file already not exist.

You can use touch -d TIME or –date=TIME options to use TIME instead of the current time. Time can contain month names, time zones, ‘am’ and ‘pm’, ‘yesterday’, etc.

You can use touch -r FILE or –reference=FILE option to use the times of the reference FILE instead of the current time. If this option is combined with the ‘–date=TIME’ (‘-d TIME’) option, the reference FILE’s time is the origin for any relative TIMEs given, but is otherwise ignored.

You can use touch -t [[CC]YY]MMDDHHMM[.SS] option to use the argument (optional four-digit or two-digit years, months, days, hours, minutes, optional seconds) instead of the current time. If the year is specified with only two digits, then CC is 20 for years in the range 0 … 68, and 19 for years in 69 … 99. If no digits of the year are specified, the argument is interpreted as a date in the current year.

You can use touch -h or –no-dereference options to change the timestamps of a symbolic link, rather than what the link refers to. When using this option, empty files are not created, but option ‘-c’ must also be used to avoid warning about files that do not exist.

Hope you have enjoyed this article. In the next blog post, we will discuss the watch command in Linux.