touch is a command-line tool that changes the access and/or modification times of the specified files. If a file does not exist, it is created empty unless the --no-create flag is specified. It mimics the behavior of the GNU touch utility, with support for various timestamp sources like reference files, POSIX stamps, or date strings.
- Create new files or update timestamps of existing files.
- Support for GNU-compatible flags and options, including
--access,--modification,--date,--reference,--stamp, and more. - Modular design with separate packages for CLI handling (Cobra), core logic, filesystem interactions, timestamp parsing, and platform-specific functionality.
- Comprehensive unit tests for CLI logic, timestamp calculation, and filesystem operations.
- Cross-platform compatibility, with notes for Windows-specific limitations (e.g.,
--no-dereferenceis unsupported on Windows).
Install touch using Go:
go install github.com/nicholas-fedor/touch@latestThis places the touch binary in your $GOPATH/bin (e.g., ~/go/bin/).
Create or update a file with current time:
touch file.txt| Flag | Description |
|---|---|
| -a, --access | Change only the access time. |
| -m, --modification | Change only the modification time. |
| --time string | Change the specified time: access, atime, use (like -a); modify, mtime (like -m). |
| -c, --no-create | Do not create any files. |
| -h, --no-dereference | Affect each symbolic link instead of any referenced file (unsupported on Windows). |
| --f | (Ignored for compatibility with GNU touch). |
| -r, --reference string | Use this file's times instead of current time. |
| -t, --stamp string | Use [[CC]YY]MMDDhhmm[.ss] instead of current time. |
| -d, --date string | Parse ARG and use it instead of current time. |
| -v, --version | Output version information and exit. |
| --help | Show help message. |
- Change only access time:
touch -a file.txt- Set a specific date and time:
touch -d "2025-07-13 14:30" file.txt- Use times from a reference file:
touch -r ref.txt file.txt- POSIX stamp format:
touch -t 2507131430 file.txt- Obsolete usage (treated as POSIX stamp):
touch 2507131430 file.txtFor more details, run --help or see the GNU touch manual.
Clone the repository and build:
git clone https://github.com/nicholas-fedor/touch.git
cd touch
go build -o touch ./cmdRun locally:
./touch- Go 1.22 or later (for module support).
This project is licensed under the GNU Affero General Public License v3.0 — see the LICENSE file for details.
Contributions are welcome! Please submit issues or pull requests on GitHub.
Make sure to run tests before submitting:
go test ./...Special thanks to Maria Letta for providing an awesome collection of Go gophers.