Introduction to PowerShell for Unix People by Powershell.org - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

9. commands detail - f

find

The bash find command has loads of functionality - I could possibly devote many pages to Powershell equivalents of the various options, but at it’s simplest the bash find does this:

img124.png

The simplest Powershell equivalent of the bash find is simply to stick a -recurse on the end of a dir command

img125.png

If you want Powersehll to give you output that looks more like the Unix find then you can pipe into | select fullname

img126.png

img127.png

for

for loop - start, stop, step

The equivalent of this bash:

img128.png

…is

img129.png

for loop - foreach item in a list

For the Bash

for I in Chelsea Arsenal Spuds do   echo $I done

the equivalent Powershell is:for

each ($Team in ("Chelsea", "Arsenal", "Spuds")) {write-output $Team}

for loop - for each word in a string

For the bash:

img130.png

…the equivalent Powershell is:

img131.png

for loops - for lines in a file

Bash:

img132.png

Posh:

img133.png

or:

img134.png

for loop - for each file in a folder

Bash:

img135.png

Posh:

img136.png