Skip to content

Category: PowerShell

The Windows Subsystem for Linux instance has terminated.

After putting my laptop into hibernation or sleep mode, Ubuntu running on my Windows 11 machine would become unresponsive. Attempting to restart it resulted in the error:

“The Windows Subsystem for Linux instance has terminated.”

After some troubleshooting, I found a way to relaunch it:

Steps to Restart WSL

Open a PowerShell prompt.

Check the status of your WSL instances by running:

wsl -l -v

Example output:

NAME                   STATE           VERSION
* Ubuntu-22.04           Running         2
  docker-desktop-data    Stopped         2


Shut down WSL completely with:

wsl --shutdown

Verify that WSL has stopped by running:

wsl -l -v

Example output:
NAME                   STATE           VERSION
* Ubuntu-22.04           Stopped         2
  docker-desktop-data    Stopped         2


Once WSL has been stopped, you can now reopen Ubuntu, and it should work as expected.

Leave a Comment

Delete Multiple branches from Git

I create a folder structure when creating branches, xavier/xxxx. I wanted to delete all those branches since they were old. I ended up doing it one by one, no matter what tool I used, and it was taking too long.

Here is a Powershell script that helped.

# Get all remote branches, filter for those starting with "xavier/"
$branches = git branch -r | Where-Object { $_ -match 'xavier/' } | ForEach-Object {
    # Remove any leading/trailing whitespace and remove the "origin/" prefix
    $_.Trim() -replace '^origin/', ''
}

# Loop through each branch and delete it from the remote repository
foreach ($branch in $branches) {
    git push origin --delete $branch
}
Leave a Comment

My first PowerShell command – Rename Files

This is my first power shell command. I wanted to remove all spaces from the file names in my current directory.

Dir | Rename-Item –NewName { $_.name –replace " ","" }

Here is more information on the Rename-Item command.

http://technet.microsoft.com/en-us/library/hh849763.aspx

Leave a Comment