Skip to content

ChristopherHeng/touch

Repository files navigation

Touch (for Windows)

Contents

What is Touch?

Touch changes the last accessed and last modified time on the file or files named in its arguments. If a file does not exist, it is created. (This default behaviour can be changed through its option flags.)

Quick Start Tutorial: How to Use Touch

To update the last accessed and last modified time on a file called file_to_change.c to the current date and time, use:

touch file_to_change.c

To change the times to a specific date and time:

touch -d "2026-02-01 08:01:00" file_to_change.c

The above command line changes both the accessed and modified time of file_to_change.c to 1 February 2026, 8:01:00 local time.

To only change the last modified time on a file to a particular date and time specified in UTC:

touch -m -d "2025-12-25 18:50:25Z" file_to_change.c

The "Z" that is affixed to the end of the date-time string specifies that the date and time is in UTC, and the -m option tells touch to only change the last modified time of the file. The latter is changed to 25 December 2025, 18:50:25 UTC.

You can also change the file to the same file times as another file:

touch -r announcement.txt *.c *.h

The above command line instructs touch to use the last accessed and modified times of announcement.txt for all files ending with .c and .h in the current directory.

Touch supports numerous other options, described in more detail in the User Manual below. You can also get a brief summary of those options by typing:

touch --help

User Manual

Usage

touch [options] file...

Options

-a, --access, --atime

This option causes touch to change the last accessed time of the file. If neither -a nor -m is specified, touch will update both the last accessed and last modified times.

-c, --no-create

By default, if a file named on the command line does not exist, touch creates an empty file with that name and sets the file times accordingly. If this is not desirable, use this option, which will suppress the file creation. In such a case, if the file does not exist, touch will silently skip to the next file, if any, and treat the operation as having succeeded. That is, if this is the only file named, touch will do nothing and return an exit code of 0, indicating success.

-d <date>, --date=<date>

Use the specified <date> instead of the current date and time as the file time. <date> must be formatted as follows:

YYYY-MM-DDThh:mm:ss[.frac][Z]

or

YYYY-MM-DDThh:mm:ss[,frac][Z]
  • YYYY is the 4-digit year
  • MM is the 2-digit month with a value from 01 to 12
  • DD is the 2-digit day with a value from 01 to 31
  • T is either the literal 'T' or a single space
  • hh is the hour with a value from 00 to 23
  • mm is the minute with a value from 00 to 59
  • ss is the second with a value from 00 to 59, or 60 if it's a leap second
  • the optional [.frac] or [,frac] is the decimal point (either '.' or ',') followed by a fractional second
  • the optional [Z] is the literal 'Z' if the date and time is in UTC; if absent, it is assumed to be local time

-h, --no-dereference

If the file named on the command line is a symbolic link, by default, touch will operate on the file pointed to by the link. If you want it to change the file times on the symbolic link itself, use this option.

-m, --modify, --mtime

This option causes touch to change the last modified time of the file. If neither -a nor -m is specified, touch will update both the last accessed and last modified times.

-r <ref_file>, --reference-file=<ref_file>

Touch will use the file times of <ref_file> instead of the current date and time.

-t <time>, --time=<time>

Use the specified <time> instead of the current date and time as the file time. <time> must be formatted as follows:

[[CC]YY]MMDDhhmm[.ss]
  • the optional CC is the first 2 digits of the year
  • the optional YY is the second 2 digits of the year; it is required if the first 2 digits is specified
  • MM is the 2-digit month with a value from 01 to 12
  • DD is the 2-digit day with a value from 01 to 31
  • hh is the hour with a value from 00 to 23
  • mm is the minute with a value from 00 to 59
  • the optional ss is a '.' followed by the second with a value from 00 to 59, or 60 if it's a leap second

The date and time specified by this option is always treated as local time.

--help

Show a brief summary of the usage and options.

--version

Show the current version.

Exit Codes

Touch returns an exit code of 0 if there was no error processing every file on the command line and 1 otherwise.

Compatibility

Touch implements the functionality of the POSIX touch utility as specified in POSIX 1003.1-2024.

It also supports the -h option that is found in BSD touch and GNU touch. ("BSD touch" in this case refers to the touch found on BSD systems, like FreeBSD, OpenBSD, etc, and also macOS. "GNU touch" is from GNU's coreutils package, and is the touch that is usually found on Linux systems.) In addition, it has long option equivalents to all the short options, so that they are easier to remember.

As long as you only use the date/time formats and short options (that is, -a, -c, -d, -m, -r and -t) mentioned in the POSIX standards, your command lines should be portable to all these implementations of touch (BSD, GNU and this one).

If you don't care about portability, then it doesn't matter if you use the extensions found in any of the three versions (they all have their unique additions), so long as you remember that they may not be present in the other versions. For example, long options are not found in the BSD version, and I have additional long options not found in the GNU version. And the GNU version supports date formats not supported in either the BSD or my version. In fact, the GNU implementation of -h also differs slightly from the BSD and my version (only when used with -r and a reference file that is also a symbolic link).

Compiling Touch

You do not need to compile touch if you don't want to. A precompiled 64-bit version of it is available on the Releases page. Touch requires a minimum of Windows 10 version 1809, regardless of whether you compile it yourself or get the pre-packaged version.

For those who want to build it themselves, you will need either Visual Studio or MinGW-w64. First get the source zip from the releases page or clone the Touch repository.

If you are using Visual Studio, do the following:

nmake -f makefile.vs all

You can also use Clang to compile it:

nmake -f makefile.vs CC=clang-cl all

Those using MinGW-w64 should do the following instead:

make -f makefile.min all

Depending on which MinGW-w64 distribution you are using, you may have to type mingw32-make instead of make.

The precompiled version was built using Visual Studio.

Author and Copyright

Copyright 2026 by Christopher Heng. All rights reserved.
Distributed under the terms of the GNU General Public License Version 3.

You can get the latest version of Touch from its repository at
https://github.com/ChristopherHeng/touch

Precompiled binaries can be found on the releases page, at
https://github.com/ChristopherHeng/touch/releases

About

Touch changes the last accessed and last modified time on the file or files named in its arguments. If a file does not exist, it is created.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors