Saturday, March 22, 2008

Comparing Unix/Linux, PowerShell, and DOS Commands

The following lists some of my favorite Unix commands and maps the associated PowerShell and DOS commands, if any. If there is one Unix command I would love to have in PowerShell, it is the grep command with its regular expression support. I have noticed significant improvement in Vista's search capabilities compared to earlier versions of Microsoft operating systems that I have used and I would love to see that harnessed in PowerShell so that I could use it from the command line. The table appears a ways down, so scroll down to it.

UPDATE (24 March 2008): Note that I have updated this table with information on a grep equivalent and on the availability of less as an extension. Thanks to Kirk Munro for pointing both of these out (see Comments) and to Jeffrey Snover for his write-up of Select-String at http://blogs.msdn.com/powershell/archive/2008/03/23/select-string-and-grep.aspx.
Thanks also to Marco Shaw for pointing out that start-transcript (which can be closed with stop-transcript) provides functionality like Unix's script command. Thanks to Jonathan for mentioning tasklist as an alternative to ps and mentioning F7 for a graphical presentation of history commands.
























Unix/LinuxPowerShellWindows Vista DOS
lsls
dir
dir
cpcp
copy
copy
mvmv
move
move
rmrm
del
del
netstatnetstatnetstat
manman
help
help
psps
tasklist
tasklist
fingerfingerfinger
script
(stop with CTRL-D)
start-transcript
(stop with stop-transcript)
 
clearclear
cls
cls
catcat
type
type
history / hhistory / h
F7
F7
unzipunzipunzip
zipzipzip
teetee 
grepSelect-String 
moremoremore
lessless (extension) 
editeditedit
killkill
taskkill
taskkill


Type ‘man’ without any options in PowerShell command-line
to see long list of supported commands and scripting keywords.



The Windows PowerShell Quick Reference and Getting Started with Windows PowerShell are also useful resources.

7 comments:

Unknown said...

Hi Dustin,

Check out the post on the PowerShell Team blog, here:
http://blogs.msdn.com/powershell/archive/2008/03/23/select-string-and-grep.aspx.

Jeffrey Snover points out how Select-String is used as the PowerShell equivalent of grep (and how there should be an alias linking grep to Select-String in PowerShell).

Also if you install the PowerShell Community Extensions (http://www.codeplex.com/PowerShellCX), you'll get less.exe installed and ready for use in PowerShell as well.

The only one I'm not sure about in your list is script.

Hope this helps.

Kirk Munro [MVP]
Poshoholic
http://www.poshoholic.com

@DustinMarx said...

Kirk,

Thanks for pointing out the grep equivalent and the availability of less. I'll definitely be looking into both. I appreciate you writing the comment up to let me know and to make this blog entry more complete.

Dustin

marco.shaw said...

script -> PSH: start-transcript

Unknown said...

tasklist is the CMD equivalent of ps, and F7 displays CMD's command history.

@DustinMarx said...

Thanks, Marco and Jonathan. I have added the information you provided to the table above.

Dustin

Unknown said...

For start-transcript check this also - http://dmitrysotnikov.wordpress.com/2008/02/21/make-powershell-record-everything-you-do/

John J. Kavanagh said...

Shouldn't gci be listed as a PS equivelant/like for ls as well?