Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我了解dir(Get-ChildItem) 和Sort-Objectcommand-let,但我需要将前x 个文件输出到一个文件。
dir
Sort-Object
例如,如果我按 排序LastWriteTime,如何将输出限制为仅前 5 个文件?
LastWriteTime
(无需访问子文件。)
听起来你想要:
ls | ?{! $_.psiscontainer} | sort -property lastwritetime | select -first 5
使用 PS3:
PS III> ls -file | sort lastwritetime | select -first 5
另外的选择:
PS III> (ls -file | sort lastwritetime)[0..4]