FactorPad
Build a Better Process

Linux touch Command Summary with Examples

Linux touch allows you to update file timestamps.
  1. Purpose - Learn what touch is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with touch.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 23, 2021
In this tutorial on Linux touch, 16 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / touch-command.html


An ad-free and cookie-free website.


Examples of the Linux touch Command

Beginner

Learn to update timestamps and create empty files at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux touch Command Summary with Examples (3:57)

Video Script

The Command and Why You Need It

Our sixteenth word, or command to memorize is touch from the category Files.

touch allows you to update file timestamps.

Common Linux touch Options
-options description
--help Print help screen
--date Update to a different date or time other than now

Recall from our last video (tutorial) we saw our first command related to time, now we'll be able to edit the timestamps saved to those files.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The touch command has 11 options and the argument is the file you'd like to edit, and if you think about it, the argument is required here, as you can't touch nothing, right?

As with many commands, the double-dash --help option is available. If no option is specified, the default update is to the current time.

With the double-dash --date option you can update to a different date using a human-readable date format, like "next Monday".

So why is touch an important command? Well, touch is a helpful command when creating scripts and surprisingly is a great way to create a new empty file as well. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go, let's start with that cool feature of the touch command, creating a file. Let's make one called video16.txt and then list files using ls -og to simplify the view so we can see the timestamps.

$ touch video16.txt $ ls -og total 8 -rw-r--r-- 1 100 Oct 10 18:42 video11.txt -rw-r--r-- 1 0 Oct 10 21:15 video16.txt -rw-r--r-- 1 176 Oct 4 18:14 video5.txt

Notice, the date is October 10, and how the file size is zero. Interesting, isn't it?

Now, let's try something fun. Let's update, using touch --date="yesterday" and the file name video16.txt.

$ touch --date="yesterday" video16.txt $ ls -og total 8 -rw-r--r-- 1 100 Oct 10 18:42 video11.txt -rw-r--r-- 1 0 Oct 9 21:16 video16.txt -rw-r--r-- 1 176 Oct 4 18:14 video5.txt

And ls -og again, and voila, the timestamp now reads October 9.

A Final Tip

Okay now you know how to use touch. And you know the syntax for commands, options and arguments.

One last tip about the touch command. Files actually have three timestamps, the first one is associated with changes to contents, next permissions, and last the read time. We'll revisit this topic later.

Okay, thanks for visiting today. I hope this was a fun introduction to the touch command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

If you found value here, consider subscribing to our YouTube Channel as that will help to spread the word. For updates follow @factorpad on Twitter.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / touch-command.html


linux touch
touch command
linux touch command
linux touch tutorial
linux touch syntax
linux file timestamp
find mtime
file mtime
file atime
file ctime
touch file
terminal touch command
linux commands tutorial
man touch linux
linux touch example
linux atime
linux mtime
linux ctime

A newly-updated free resource. Connect and refer a friend today.