FactorPad
Faster Learning Tutorials

Linux touch command summary with examples

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.
Paul Alan Davis, CFA, October 10, 2016
Updated: July 27, 2018
In this tutorial, 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 Next

~/ home  / tech  / linux essentials  / touch command


The Linux touch command

Beginner

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

Video Tutorial

Linux touch command summary with examples (3:57)

Videos can also be accessed from the YouTube Playlist.

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.

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.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the date command, hit Back.
  • To learn about the file command and examine whether a file is an executable or ASCII text file, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / touch command



 
 
Keywords:
Linux touch command
unix touch command
linux touch syntax
linux create empty file
linux update timestamp
linux file timestamp
linux set file time
linux commands tutorial
find atime linux
find mtime linux
find ctime linux
linux stat
terminal touch command
linux touch example