4 ms·
> ls | sort <now it gets complicated here> In Powershell, from memory: ls | sort -property time https://msdn.microsoft.com/en-us/powershell/reference/5.1/m
by nailer 10y ago
> ls | sort <now it gets complicated here>
In Powershell, from memory:
ls | sort -property time
https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/sort-object https://msdn.microsoft.com/en-us/powershell/reference/5.1/mi...
- flukus 10y ago"man ls" in bash showed me what I need, doing the same in powershell gave me some nonsense about Get-ChildItem.
- sha666sum 10y agoIn PowerShell, ls is an alias for Get-ChildItem.
- flukus 10y agoThat doesn't really help me though does it? "get-help Get-ChildItem" isn't any better. "get-help Get-ChildItem -examples" is a bit better, "get-help Get-ChildItem -detailed" is what I'm after, why on earth doesn't "man ls" map to that? It's the same story with sort. Know how am I supposed to know what type ls returns and what properties are available? For that matter, how am I supposed to know what type of object I'm dealing with? Time isn't displayed by the command and is different to LastWriteTime, how do I discover that it's a property? So far in this ultra simple example powershell is looking over complicated and under featured.
- ksk 10y ago>Time isn't displayed by the command and is different to LastWriteTime, how do I discover that it's a property? The command you're looking for is Get-Member or gm. In this case 'ls | gm' will give you what you want. In much the same way that you were told to type 'man', rather than type all combinations of three letter words, you'll have to either pickup a book or read an article to learn a system. As a novice you can't expect to be proficient on day 1 now can you?
- flukus 10y agoOk, I did "ls | gm" and it still doesn't list the time property and there is no documentation on what the properties mean (to be fair, they are self explanatory in this case). It also appears that it can return multiple types, which could add some complication. You're right that bash/unix requires some learning, but in my experience it requires less upfront learning and it plateaus fairly quickly, when I try and do something twice as complex it will only by 1.1 times as complicated. Powershell on the other hand doesn't seem to plateau, something twice as complex tends to be twice as complicated (or more).
- nailer 10y ago> Ok, I did "ls | gm" and it still doesn't list the time property LastAccessTime Property datetime LastAccessTime {get;set;} LastAccessTimeUtc Property datetime LastAccessTimeUtc {get;set;} LastWriteTime Property datetime LastWriteTime {get;set;} LastWriteTimeUtc Property datetime LastWriteTimeUtc {get;set;}
- ygra 10y agoThere is no Time property. Your initial command 'ls | sort -property time' simply sorts by nothing, i.e. effectively the same as using sort { $null }. I think that's what they were so confused by.
- nailer 10y ago> how do I discover that it's a property? There's a bunch of properties displayed by default, but if you want to see all of them: ls | select * Since ls (gci, get-childitem) can list Environemnt variables, Registry entries, etc (which is awesome) these all have different properties. ls Env: | select * However I do see your point: the docs could be better about explaining that.
- ksk 10y agoWhat you read might not work on another UNIX. BSD has its own semantics making writing cross platform UNIX scripts (depending on how far you stray from POSIX) a pain. Though I admit, its not fair to compare it to a single vendor system like NT. :)
- flukus 10y agoWouldn't the man pages for bsd be updated to reflect any changes? I'm not sure if PowerShell will fare much better when it comes to program inconsistencies.
- MichaelMoser123 10y agoNever used powershell, is it really that hard to create an alias in powershell? http://stackoverflow.com/questions/24914589/how-to-create-permanent-powershell-aliases http://stackoverflow.com/questions/24914589/how-to-create-pe...
- ygra 10y agoAliases in PowerShell only alias the command itself and can not supply any parameters or other processing. This makes certain things nice, in that Get-Help works straightforward with aliases, and tab completion for arguments as well, but it complicates the case where you want to supply default arguments or do other things. You can run Get-Content Function:help to see how it can be done. Essentially it consists of: - Writing a function - Redirecting to the correct help topic - Replicating all parameters and parameter sets so that tab completion works Of course, if help and completion are irrelevant to you (wouldn't work correctly out of the box for bash either, I guess), then it just consists of writing a wrapper function instead of setting an alias.
- nailer 10y agoLike bash (where aliases are also limited) most people list make functions.
- cestith 10y agoHence, as your parent comment said, you've shifted complexity into sort.