PowerShell Vs Bash
PowerShell Vs Bash
∑ PowerShell Tutorial
PowerShell vs Bash
By Xah Lee. Date: 2009-07-26. Last updated: 2016-08-19.
This pages shows the equivalent of PowerShell for common unix commands
related to text processing.
Simple Commands
The following bash commands have PowerShell alias. (but the options may not be
the same)
cd
pwd
ls
pushd
popd
cp
rm
rmdir
mv
cat
echo
set
ps
kill
clear
man
◇ split ?
◇ find . -type f ?
◇ find . -name "*html" gci . -Recurse -name -include *html
◇ find . -size 0 ls . -recurse | where {$_.length -eq 0}
Work In Progress
Note: this page is a mess. It's work in progress. (started when i wished to convert
my log processing bash script to PowerShell)
Detail
touch
Redirect “>”
http://xahlee.info/powershell/PowerShell_for_unixer.html 2/5
3/21/2018 PowerShell vs Bash
Note that, by default, the PowerShell redirect operator ">" creates files with little
endian utf-16 encoding, and lines are hard-wrapped at 80 chars, and line ending
uses Windows convension of "\r\n" (ascii 13 and 10).
On unixes, the conventional file encoding is utf-8, and lines are not hard-wrapped
(sometimes truncated (deleted) silently), and line ending uses "\n" (ascii 10).
However, the line ending used is still "\r\n". To create unix line ending of just "\n",
use:
cat
Unix “cat” can be used to read a file, or join several files. PowerShell equivalent is
“get-content” with alias “cat” too.
Note that by default, PowerShell assumes ascii. You can set your
$OutputEncoding like this:
Thanks to Shivashis Saha for addition on “cat”. He also sends the following:
split
For example, if you want to split a line based on ":", you can use the following line:
Super thanks to Jeffrey Snover of Microsoft for helping on about 10 of the items.
(Jeffrey's the inventor of PowerShell)
http://xahlee.info/powershell/PowerShell_for_unixer.html 3/5
3/21/2018 PowerShell vs Bash
PowerShell
1. Install, Win, Mac, Linux
2. PowerShell Help
3. PowerShell as cmd.exe
4. list Alias, find Alias
5. Piping Output and Input
6. Environment Variables
1. Predefined Variables
2. Creating PowerShell Scripts
PowerShell vs Bash
http://xahlee.info/powershell/PowerShell_for_unixer.html 4/5
3/21/2018 PowerShell vs Bash
6 Comments xahlee.org
1 Login
Sort by Best
Recommend ⤤ Share
LOG IN WITH
OR SIGN UP WITH DISQUS ?
Name
am sure it is, or with a pipe. I haven't used PowerShell for years. Am back on linux now.
△ ▽ • Reply • Share ›
∑XAH
© 1995, …, 2018 Xah Lee.
http://xahlee.info/powershell/PowerShell_for_unixer.html 5/5