/ factorpad.com / tech / linux-essentials / touch-command.html
An ad-free and cookie-free website.
Beginner
Learn to update timestamps and create empty files at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux touch Command Summary with Examples (3:57)
Our sixteenth word, or command to memorize is touch
from the category Files.
touch
allows you to update file
timestamps.
-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.
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.
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
.
And ls -og
again, and voila, the
timestamp now reads October 9.
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.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
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.
date
command,
hit Back.file
command
and examine whether a file is an executable or ASCII text file, click
Next./ factorpad.com / tech / linux-essentials / touch-command.html
A newly-updated free resource. Connect and refer a friend today.