ISO27001:2013
Certified Supplier

FIND OUT MORE

We're an ISO27001:2013 Certified Supplier

blog-post-featured-image

The touch command is one of the long-established commands that, by default, either creates a file if it doesn’t exist or updates the access and modification times of a file if it does. It’s useful for those situations where behaviour depends upon either the existence or otherwise of a file, or the date of it:

By default, the times set are the current date and time:

Specify the Date

Its’s possible to set the timestamp of the file to any arbitrary value:

Show the Time

In the final example above the year is shown in preference to the time because the date of this file in not the current year. One way to see the access and last modified times is with the stat command:

We can customise the stat command to show only the modified and last access times by specifying a format:

Other Ways to Specify Timestamps

It may be more convenient to use the -t option, which allows the time/date to be specified in the format[[CC]YY]MMDDhhmm[.ss]:

By default, both the last access time and the modification time are set with touch. That can be changed by using the -a (change only the access time) or -m (only the modification time) options:

In Closing

Both stat and touch are handy commands to have up your sleeve for when they’re really needed.

Could This Tech Tip Be Improved?

Let us know in the comments below.

Leave a Reply

Your e-mail address will not be published. Required fields are marked *