Friday, May 16, 2025

Touch in Powershell

Linux has Touch. I needed touch today in PowerShell. This is what I came up with. 

function touch {
    param (
        [Parameter(Mandatory=$true, ValueFromRemainingArguments=$true)]
        [string[]]$Paths
    )
    foreach ($Path in $Paths) {
        $dir = Split-Path $Path
        if (-not (Test-Path $dir)) {
            New-Item -ItemType Directory -Path $dir -Force | Out-Null
        }
        if (-not (Test-Path $Path)) {
            New-Item -ItemType File -Path $Path -Force | Out-Null
        }
    }
}

Add it to your PowerShell profile by pasting the function into your current PowerShell window then:

touch $PROFILE
notepad $PROFILE

Paste the function into the text file and save it. Then all future PowerShell sessions can use:

touch <path to your file>

One thing I built into it was to build out the intermediary folders in case they don't exist.

Monday, May 5, 2025

Using Screen in Linux

Create session:

screen -S <sessionname>

Disconnect from session

Ctrl+A+D

Reconnect to session

screen -r <sessionname>