commands detail - t

tail

1 gc file.txt | select-object -last 10

gc is an alias for get-command

tail -f

1 gc -tail 10 -wait c:\windows\windowsupdate.log 

tee

The Powershell equivalent of the unix tee is tee-object….which, by default is aliased to tee

So you can do this:

1 get-process | tee c:\temp\test_tee.txt

…to both get a list of processes on your screen and get that output saved into the file in c:\temp

time

The Powershell equivalent of the bash shell ‘time’ is ‘measure-command’.

So, in bash you would do this:

1 time egrep ORA- *log

….and get all the egrep output, then

1 real    0m4.649s
2 user    0m0.030s
3 sys     0m0.112s

In Powershell, you would do this

1 measure-command {select-string ORA- *.sql}

…and get…

 1 Days              : 0
 2 Hours             : 0
 3 Minutes           : 0
 4 Seconds           : 0
 5 Milliseconds      : 105
 6 Ticks             : 1057357
 7 TotalDays         : 1.22379282407407E-06
 8 TotalHours        : 2.93710277777778E-05
 9 TotalMinutes      : 0.00176226166666667
10 TotalSeconds      : 0.1057357
11 TotalMilliseconds : 105.7357

…you don’t get the ‘user CPU’ time and ‘system CPU’ time, but you do get the added bonus of seeing how long the command took rendered as a fraction of a day!

touch - create an empty file

1 set-content -Path c:\temp\new_empty_file.dat -Value $null

I found the set-content command at <a href=”http://superuser.com/questions/502374/equivalent-of-linux-touch-to-create-an-empty-file-with-powershell”>Super User</a>, the contributor being <a href=”http://superuser.com/users/23133/techie007”>user techie007</a>

touch - update the modified date

1 set-itemproperty -path c:\temp\new_empty_file.dat -name LastWriteTime -value $(get-d\
2 ate)

I got this from a comment by <a href=”https://twitter.com/manung”>Manung Han</a> on the <a href=”http://blog.lab49.com/archives/249#comment-1076”>Lab49 Blog</a>. Doug Finke shares <a href=”http://blog.lab49.com/archives/249”>touch function</a> in a later comment on the same post that fully implements the linux command.