Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting an alias with attributes in PowerShell

Tags:

powershell

I wanted to set an alias for listing files in the directory, but Set-Alias -name lf -value ls -file does not seem to work. I intend to use this the Unix alias way.

like image 444
Antony Thomas Avatar asked May 25 '26 15:05

Antony Thomas


1 Answers

An alias can't do that. From the help for Set-Alias:

You can create an alias for a cmdlet, but you cannot create an alias for a command that consists of a cmdlet and its parameters.

However, using a technique called "splatting", a function can do it easily:

function lf {
  ls -file @args
}

For more information, see help about_splatting.

like image 111
Mike Zboray Avatar answered May 28 '26 09:05

Mike Zboray



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!