A PowerShell implementation of the Unix touch command for Windows. This module provides the familiar touch functionality to PowerShell users who want to create new files or update file timestamps.
- Create files: Quickly create new empty files
- Update timestamps: Update the last write time of existing files to the current date and time
- Pipeline support: Accept file paths from the pipeline
- Cross-platform: Works with PowerShell on Windows, and compatible with PowerShell Core
Install-Module -Name TouchCmd -Scope CurrentUser-
Clone or download this repository
-
Copy the module folder to your PowerShell modules directory:
- Windows:
$PROFILE\..\Modules\TouchCmd\ - Or place in any directory in your
$PSModulePath
- Windows:
-
Import the module:
Import-Module TouchCmd
touch "C:\path\to\newfile.txt"touch "C:\path\to\existingfile.txt""file1.txt", "file2.txt", "file3.txt" | touchforeach ($file in @("test1.txt", "test2.txt", "test3.txt")) {
touch $file
}Specifies the path of the file to create or touch. Accepts values from the pipeline.
touch -Path "C:\path\to\file.txt"- PowerShell 3.0 or later
- Windows PowerShell or PowerShell Core
# Create a new file in the current directory
touch "myfile.txt"
# Update the timestamp of an existing file
touch "C:\Users\YourName\Documents\report.docx"
# Create files using pipeline
@("file1.txt", "file2.txt") | touch
# Create a file with a relative path
touch ".\output\results.txt"The touch function:
- Checks if the file exists using
Test-Path - If the file exists, updates its
LastWriteTimeproperty to the current date and time - If the file doesn't exist, creates a new empty file using
New-Item
Contributions are welcome! Feel free to submit issues or pull requests to improve this module.
This module is based on the Unix touch command concept. Original PowerShell implementation adapted from Cassidy Williams' blog post.
- Eduardo DONATO
For issues, questions, or suggestions, please open an issue on the project repository.