Robert Elder Software Inc.
  • Home
  • Store
  • Blog
  • Contact
  • Home
  • Store
  • Blog
  • Contact
  • #linux
  • |
  • #commandline
  • |
  • #softwareengineering
  • |
  • #embeddedsystems
  • |
  • #compilers
  • ...
  • View All >>

Intro To 'touch' Command In Linux

2023-04-30 - By Robert Elder

     I use the touch command to create empty files or update timestamps.  For example, I can use the touch command to quickly create an empty '__init__.py' file to indicate that this directory should be treated as a python package:

touch __init__.py

     and the output is:

ls -l

     and the output from the 'ls' command now shows the following:

total 0
-rw-rw-r-- 1 robert robert 0 May  1 22:46 __init__.py

     You can also use the touch command to create multiple files at once, like this:

touch main.py README.txt text.csv
ls -l

     Now the output from running 'ls' shows the following:

total 0
-rw-rw-r-- 1 robert robert 0 May  1 22:46 __init__.py
-rw-rw-r-- 1 robert robert 0 May  1 22:47 main.py
-rw-rw-r-- 1 robert robert 0 May  1 22:47 README.txt
-rw-rw-r-- 1 robert robert 0 May  1 22:47 text.csv

     The touch command can also be used on an existing file to update its last modified timestamp.  For example, if we focus on the last modified timestamp of the 'main.py' file:

ls -l main.py
-rw-rw-r-- 1 robert robert 0 May  1 22:47 main.py

     Now, if I run the 'touch' command on this file again:

touch main.py
ls -l main.py

     The output from the 'ls' command shows an updated last modified timestamp:

-rw-rw-r-- 1 robert robert 0 May  1 22:53 main.py

     As you can see from the above output, the last modified timestamp was updated to 'May 1, 22:53' which is different from the value of 'May 1, 22:47' that it had previously.

     This feature of the 'touch' command is useful since some programs like GNU make or rsync will change their behavior according to the last modified timestamps of certain files.

     And that's why the touch command is my favorite Linux command.

Intro To 'stty' Command In Linux
Intro To 'stty' Command In Linux
Published 2023-10-04
Terminal Block Mining Simulation Game
$1.00 CAD
Terminal Block Mining Simulation Game
Intro To 'nproc' Command In Linux
Intro To 'nproc' Command In Linux
Published 2023-07-15
Intro To 'comm' Command In Linux
Intro To 'comm' Command In Linux
Published 2023-09-06
How To Force The 'true' Command To Return 'false'
How To Force The 'true' Command To Return 'false'
Published 2023-07-09
A Surprisingly Common Mistake Involving Wildcards & The Find Command
A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01
Intro To 'chroot' Command In Linux
Intro To 'chroot' Command In Linux
Published 2023-06-23
Join My Mailing List
Privacy Policy
Why Bother Subscribing?
  • Free Software/Engineering Content. I publish all of my educational content publicly for free so everybody can make use of it.  Why bother signing up for a paid 'course', when you can just sign up for this email list?
  • Read about cool new products that I'm building. How do I make money? Glad you asked!  You'll get some emails with examples of things that I sell.  You might even get some business ideas of your own :)
  • People actually like this email list. I know that sounds crazy, because who actually subscribes to email lists these days, right?  Well, some do, and if you end up not liking it, I give you permission to unsubscribe and mark it as spam.
© 2025 Robert Elder Software Inc.
SocialSocialSocialSocialSocialSocialSocial
Privacy Policy      Store Policies      Terms of Use