Justin Hoyt
Justin Hoyt

Reputation: 158

Get-ChildItem to act like ls instead of ls -l

When I use Get-ChildItem in PowerShell I get a list of items in a directory formatted in rows. This list often goes off screen, forcing me to scroll up if I want to see the rest of the list or previous commands and outputs. I want to make an alias or function for ls that behaves like ls in unix. I want a compact list of names that are formatted in a tabular fashion.

I have a function that I'm working on that strings all the names together, but it doesn't format the list in a table and does not prevent names from overflowing to the next line:

function uls {
(Get-ChildItem $args[0] | select -exp name) -join "`t"
}

In sum, is there a way to get a compact ls-like output from Get-ChildItem?

Upvotes: 4

Views: 1143

Answers (1)

Bacon Bits
Bacon Bits

Reputation: 32210

Use Format-Wide, which has a default alias of fw:

ls | fw

You can control the number of columns with the -Column property:

ls | fw -c 5

Just beware that the output of that command is a string, not a collection of objects, so it wouldn't be useful for pipelining.

Upvotes: 5

Related Questions