You want the set-alias commmand in coombination with a powershell script or a function. So open a editor and write:
set-location d:\xampp\htdocs
and save this file for example to c:\Users\kumar\htdocs32.ps1 or you can create a function like this.
function htdocs32 { set-location d:\xampp\htdocs }
to execute scripts you must set the execution policy allowing scripts locally. open the powershell command line as administrator and type:
set-executionpolicy remotesigned
now you are able to set an alias for the powershell script:
set-alias htdocs c:\Users\kumar\htdocs32.ps1
and typing htdocs now will cd you into your htdocs folder
Powershell is using a verb-noun combination for the naming of so called cmdlets. The verb referse to what you want to do and the noun with what you want to do something.
To get help for the set-alias command you want to use:
get-help set-alias -full |more
and no there is no less. the other method would be reading this http://technet.microsoft.com/en-us/library/ee176958.aspx
Also to start off with power shell i recommend you to have a look at this url: http://www.powershellpro.com/powershell-tutorial-introduction/
To save the alias permanently you must save it in your users profile. first test whether a Profile is already in place using:
PS C:\> $profile
if you getting false you can create a new profile by typing:
New-Item -path $profile -type file -force
now you can edit the file
c:\Users\kumar\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
and put in the function definiton and an alias. as described above.
however setting an alias for this in linux is not neccessary. sicne there is a environmentvariable $CDPATH for bash which can be set in ~/.bahsrc .
I want to cat a file and output the line number of each line it outputs.
Use the following command:
$counter = 0; get-content .\test.txt | % { $counter++; write-host "`t$counter` $_" }
As pointed out in the comments:
- It may be better to use
write-output
instead of write-host
as this allows further processing of the output.
echo
is an alias for write-output
So the above command becomes:
$counter = 0; get-content .\test.txt | % { $counter++; echo "`t$counter` $_" }
Example output:
> type test.txt
foo
//approved
bar
// approved
foo
/*
approved
*/
bar
> $counter = 0; get-content .\test.txt | % { $counter++; echo "`t$counter` $_" }
1 foo
2 //approved
3 bar
4 // approved
5 foo
6 /*
7 approved
8 */
9 bar
>
Example output from Cygwin cat -n
for comparison:
$ cat -n test.txt
1 foo
2 //approved
3 bar
4 // approved
5 foo
6 /*
7 approved
8 */
9 bar
$
Best Answer
This is probably what you're looking for. Seems like a little effort with a search engine would've reached the same conclusion.
Or, as a shorthand:
For more information see the
Remove-Item
help page.