5 ms·
In PowerShell, ls is an alias for Get-ChildItem.
by sha666sum 10y ago
In 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 agoYep, hence: > In powershell from memory: in that comment - I was on an iPad, and didn't have access to Powershell.
- flukus 10y agoBut it worked, it didn't complain about no time property like I'd expect.
- ygra 10y agoIt's a scripting language, essentially. Reading properties that don't exist most of the time just gives you $null. That being said, while there is Set-StrictMode, it only helps in this case for directly accessing properties of objects. Indirectly via Sort-Object still doesn't raise an error, annoyingly.
- ksk 10y agoIts not for me to say what will or wont be easy for you to pickup, given your prior experience with bash. IMHO Powershell has gone so far beyond bash that its not even fair to compare them. PS has combined all the objected oriented APIs inside windows (WMI, .NET etc) and you don't have to constantly convert to and from strings, which is brittle to begin with. PS can simply pass around in-memory objects, making it far more efficient. Powershell also has real types and this helps reduce scripting errors. There are lots of nice things in powershell, so for e.g. even if you didn't know the properties, you can autocomplete after typing "ls | sort -property" and can choose one. AFAIK you can't do this on a shell that doesn't use objects. You'll find that the design of the command names is mostly consistent with verb-noun format. I'm not even a sysadmin, I do embedded systems programming, but I still appreciate some of the niceties in PS. For e.g. Reading HN : irm https://news.ycombinator.com/rss Stop all my VMs : get-vm | stop-vm Stop all processes consuming more than 1GB: ps | ?{$_.WS -gt 1GB} | kill Find all empty folders: ls -r | ?{-not($_|ls)} All the PDFs that I downloaded this month: ls -r *.pdf | ?{$_.CreationTime -gt "4/1/2017"}
- 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.