Command Detail - D
date
The Powershell equivalent of the Unix date
is
The Powershell equivalent of the Unix date -s
is
I was anticipating doing a fairly tedious exercise of going through all the Unix date formats and then working out the Powershell equivalent, but discovered the Powershell Team has effectively done all this for me. There is a Powershell option -UFormat
which stands for 'unix format'.
So the Powershell:
is the same as the *nix
This is handy...but I have found the odd difference. I tried this for a demo:
Unix:
Powershell:
I presume the discrepancy in the week of the year is to do with when the week turns - as you can see I ran the command on a Monday. Some systems have the turn of the week being Monday, others have it on Sunday.
I don't know why %Z
outputs different things....and I can't help feeling I'm being churlish pointing this out. The -UFormat option is a really nice thing to have.
df -k
A quick and dirty Powershell equivalent to 'df -k' is
A slightly prettier version is this function:
....then you can just do:
....and get
dirname
A good PowerShell equivalent to the unix dirname
is
However, this isn't a direct equivalent. Here, I'm telling Powershell to look at an actual file and then return that file's directory. The file has to exist. The unix 'dirname' doesn't care whether the file you specify exists or not.
If you type in dirname /tmp/double_winners/chelsea.doc
on any Unix server it will return /tmp/double_winners
, I think. dirname
is essentially a string-manipulation command.
A more precise Powershell equivalent to the unix 'dirname' is this
....but it's not as easy to type, and 9 times out of 10 I do want to get the folder for an existing file rather than an imaginary one.
du
While I think there are implementations of du
in PowerShell, personally my recommendation would be to download Mark Russinovich's 'du' tool, which is here:
http://technet.microsoft.com/en-us/sysinternals/bb896651.aspx
This is part of the Microsoft's 'sysinternals' suite.
Last updated