Install & Use PowerShell (How To)

Using my GameShell with my Mac introduced all sort of small “backup” files into every directory accessed through SMB. I searched the internet for a technique to recursively delete them through SSH. I came across a PowerShell script to do just that! Now my problem was how to get PowerShell into the GameShell! Not too difficult thanks to instructions from Microsoft. Rather than your having to search yourself, I’ll present the details here.

Install the Raspbian Variant

 # Install prerequisites
 sudo apt-get install libunwind8
 
 # Grab the latest tar.gz
 wget https://github.com/PowerShell/PowerShell/releases/download/v6.1.1/powershell-6.1.1-linux-arm32.tar.gz
 
 # Make folder to put powershell
 mkdir ~/powershell
 
 # Unpack the tar.gz file
 tar -xvf ./powershell-6.1.1-linux-arm32.tar.gz -C ~/powershell
 
 # Start PowerShell
 ~/powershell/pwsh

Optionally you can create a symbolic link to be able to start PowerShell without specifying path to the “pwsh” binary

 # Start PowerShell from bash with sudo to create a symbolic link
 sudo ~/powershell/pwsh -c New-Item -ItemType SymbolicLink -Path "/usr/bin/pwsh" -Target "\$PSHOME/pwsh" -Force
 
 # alternatively you can run following to create a symbolic link
 # sudo ln -s ~/powershell/pwsh /usr/bin/pwsh
 
 # Now to start PowerShell you can just run "pwsh"

Uninstall PowerShell

rm -rf ~/powershell

Clean Script

Now, with PowerShell installed, we need the script to clean our directories. Using nano, we can paste the script and save it as clean.ps1

$curDir = Split-Path -Parent $MyInvocation.MyCommand.Path
foreach ($file in Get-ChildItem -force $curDir -Recurse)
{
if (($file.Extension -match '.DS_Store') -or ($file -like '._*'))
    {
    Remove-Item $file.FullName -Force | Out-Null
    }
}

With PowerShell running execute the script from our home directory:

cd ~
pwsh

PS /home/cpi> ./clean
PS /home/cpi> exit

That’s it! I’m sure there can be a lot of additional uses for PowerShell in our GameShells.

EDIT: Unfortunately, there’s a bug in the above script. It just doesn’t work. I know PowerShell is working because the command…

PS /home/cpi> Remove-Item ~/games/4DO/._* -Force

…worked perfectly.

I will work with it to try to find the error. If anyone else can spot it, I’d appreciate a heads up.

there is already all you need to do that in gnu,

find /home/cpi -name ‘.DS_Store’ -exec rm {} ;

(also you can configure finder to not create all this dumb files on network/removable places

Thanks, but this command returns,

find: missing argument to `-exec’
Try ‘find --help’ for more information.

Of course, ‘find --help’ was of little…

sorry it miss a backslash (dropped by the board ?

find /home/cpi -name '.DS_Store' -exec rm {} \;

or

find /home/cpi -name '.DS_Store' -type f -delete

Thanks! That did it! Also, to rid the rest of the files,

find /home/cpi -name '._*' -exec rm {} \;