Skip to content

Instantly share code, notes, and snippets.

@tmlbl
Created June 26, 2017 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmlbl/6bed0f1411ca99e7f8742166eaa1dfcb to your computer and use it in GitHub Desktop.
Save tmlbl/6bed0f1411ca99e7f8742166eaa1dfcb to your computer and use it in GitHub Desktop.
Unix 'touch' command for PowerShell
function touch() {
<#
.SYNOPSIS
An analog to the UNIX 'touch' command
.DESCRIPTION
This approximates common usage of the UNIX 'touch' command. If the target
file does not exist, it is created as a regular file. If it does exist, the
last access time is set to the current time.
.PARAMETER fname
The target file path
#>
param ($fname)
If (Test-Path $fname) {
$(Get-Item $fname).LastAccessTime = $(Get-Date)
} Else {
New-Item -Type File -Name $fname
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment