DEV Community

Cover image for Bringing the Linux "touch" Command to Windows with a PowerShell Module
Eduardo Donato
Eduardo Donato

Posted on

Bringing the Linux "touch" Command to Windows with a PowerShell Module

If you frequently switch between Linux/macOS and Windows, or if you've recently migrated to Windows, you've likely experienced the frustration of opening PowerShell, instinctively typing touch file.txt, and being hit with a "command not found" error.

While PowerShell has the native New-Item cmdlet, its syntax isn't as fluid or intuitive for daily use as the simple touch command. To solve this and maintain my muscle memory, I developed the TouchCMD module and made it available on the PowerShell Gallery.

The Motivation

On Windows, the standard way to create an empty file via the terminal is:

New-Item -ItemType File file.txt
Enter fullscreen mode Exit fullscreen mode

Even with the ni alias, it still requires more effort than it should. On Linux, touch is universal, simple, and direct. I wanted that same seamless experience in PowerShell without having to rely on WSL or Git Bash for basic file manipulations.

Inspiration

The idea gained momentum after reading this post by Cassidy Williams, where she shares a simple function to emulate this behavior. I decided to take that concept and package it into a properly structured PowerShell module, making it easier to install and ensuring it persists across terminal sessions.

How to Install

Since it is published on the PowerShell Gallery, you can install it quickly with the following command:

Install-Module -Name TouchCmd -Scope CurrentUser
Enter fullscreen mode Exit fullscreen mode

Alternatively, you can clone the repository directly from GitHub.

Usage Examples

The goal is to mirror the simplicity of the original command:

Create a new file

touch C:\path\to\newfile.txt

Update the timestamp of an existing file

touch C:\path\to\existingfile.txt

Using the pipeline

"file1.txt", "file2.txt", "file3.txt" | touch

Conclusion

This is a simple project, but it removes a constant point of friction for developers working across multiple operating systems.

The code is open source, and contributions are more than welcome! If you use Windows and miss this convenience, feel free to check out the repository:

🔗 GitHub: ebdonato/touch-powershell


Translated using AI, original in Portuguese: tabnews

Top comments (0)