which <commandname> Example:
which composer
GNU “which” | Get-Command <commandname> Example:
Get-Command composer
PowerShell “Getting Environment Variables” | Find the location of an executable called <commandname> In PowerShell, Get-Command can be referred to as just “gcm ” so the example would become “gcm composer ” |
printenv
GNU “printenv” | Get-Item -Path Env:
PowerShell “Getting Environment Variables” | List all environment variables. PowerShell also supports using “ls ” to list environment variables – such as “ls env: “ |
<variablename>="<value>" Example:
HELLO="you guys" | Set-Item -Path Env:<variablename> "<value>" Example:
Set-Item -Path Env:HELLO "you guys"
PowerShell: “Change the value of an environment variable” | Sets an environment variable called <variablename> to the text <value>
PowerShell also supports using “$env:<variablename>="<value> ” ” – such as ” $env:HELLO="you guys" “ |
echo $<variablename> Example:
echo $PATH
GNU “echo” | Get-ChildItem -Path Env:<variablename> Example:
Get-ChildItem -Path Env:PATH
PowerShell “Get A Selected Environment Variable” | Show the value of an environment variable called <variablename> PowerShell also supports using “ls ” to list environment variables – such as “ls env:PATH “
|
echo <text> Example: echo "Hello there!"
GNU “echo” | Write-Output <text> Example:
Write-Output "Hello there!"
PowerShell “Write-Output” | Displays/prints a <text> string to the terminal
|
grep "<string>" <file> Example:
grep "sort code" document.txt
GNU “grep” | Select-String "<string>" <file> Example: Select-String “sort code” document.txt
PowerShell “Select-String” | Search a file <file> for the given text <string> using a regular expression
|
grep "<string>" <file> Example:
grep "sort code" document.txt
GNU “grep” | findstr /R "<string>" <file> Example:
findstr /R "sort code" document.txt
Windows Command: “findstr” | Search a file <file> for the given text <string> using a regular expression
|
ls | grep "<string>" Example:
ls | grep "\.html"
GNU “ls” | ls | Out-String -Stream | Select-String "<string>" Example: ls | Out-String -Stream | Select-String “\.html”
PowerShell “Select- String: Convert Pipline Objects” | Search a directory listing for a filename containing <string> using a regular expression
|
ls | grep "<string>" Example:
ls | grep "\.html"
GNU “ls” | dir | findstr /R "<string>" Example:
dir | findstr /R "\.html"
Windows Command: “findstr” | Search a directory listing for a filename containing <string> using a regular expression.
|
wget <url> --output-document <filename> Example:
wget https://h.tld/f.gif --output-document o.gif
GNU “wget” | Invoke-WebRequest <url> -OutFile <filename> Example:
Invoke-WebRequest https://h.tld/f.gif -OutFile o.gif
PowerShell “Invoke-WebRequest” | Save a file at a URL <url> as a local file called <filename>
|
\ (backslash) Example: a \ b
GNU “The Backslash Character” | (backtick) Example: a ` b
PowerShell “…Line Continuation in Code…” | Allows a command to be split across multiple lines using the multiline separator/line continuation character.
|
&& Example:
echo "A" && echo "B"
GNU “Lists | && Example:
Write-Output "A "&& Write-Output "B"
PowerShell “Pipeline Chain Operators” | Command chaining using pipeline operators/list operators – if the condition on the left is true/passes, then continue.
|
rm <file> Example:
rm test.tmp
GNU “rm” | Remove-Item <file> Example:
Remove-Item test.tmp
PowerShell “Remove-Item” | Deletes a file called <file>
|
unzip <file> Example:
unzip myfile.zip | Expand-Archive <file> Example:
Expand-Archive myfile.zip
PowerShell “Expand-Archive” | Extracts a .zip archive file
|
uname Example: uname -nrmo
GNU “uname” (note, the output order of uname in GNU/Linux cannot be altered) | Get-ComputerInfo
Example:
Get-ComputerInfo -Property CsDNSHostName, OsVersion, OsArchitecture, OsName | ConvertTo-Json
PowerShell “Get- ComputerInfo”
PowerShell “ConvertTo-Json” | Gets basic information about the system. For example: Computer’s “hostname” [GNU:n PS: CsDNSHostName] OS or kernel release [GNU: r PS:OsVersion] Machine/Processor type [GNU:m PS:OsArchitecture] Operating system (OS) name [GNU:o PS: OsName] |