from cmd to powershell
Below is a “minimum-to-maximum” roadmap that starts with the one-liner you need right now and ends with a set of habits that will make you “fluent” in cmd/PowerShell without memorising hundreds of switches.
- The immediate fix –
dirsorted by time
CMD (legacy, but still useful)
rem newest-last (default)
dir /od
rem newest-first (reverse)
dir /od /tw /o-d
PowerShell (the future)
# newest-first (most common want)
Get-ChildItem | Sort-Object LastWriteTime -Descending
# alias + shortest
gci | sort LastWriteTime -des
Put it in a function so you never type it again:
function lt { Get-ChildItem $args | Sort-Object LastWriteTime -Descending }
Now you just type:
lt .\Documents
- Build your own “cheat sheet” interactively
Instead of googling every time, ask the shell itself:
# discover verbs that apply to files
Get-Command *Item* | Group-Object Verb
# remind yourself of ANY parameter
Get-Help Get-ChildItem -Parameter *time*
# quick examples
Get-Help Get-ChildItem -Examples
Do this three times and the switch sticks.
- Use “one-new-thing-a-day” muscle memory
Create a tiny profile script that prints one tip when you open PowerShell:
# $PROFILE ← type this to see your profile path
notepad $PROFILE
Add:
$tips = @(
'gci | sort LastWriteTime -des',
'cls = Clear-Host',
'Ctrl+r = reverse search history',
'Get-History | ogv # open in grid'
)
Write-Host "TIP: $(Get-Random $tips)" -ForegroundColor Magenta
You’ll passively learn ~30 commands a month.
- Turn CMD habits into PowerShell habits
| CMD habit | PowerShell replacement |
|---|---|
dir /s |
gci -Recurse |
dir /b |
gci -Name |
dir /ad |
gci -Directory |
&& |
; or -and in scripts |
%VAR% |
$env:VAR |
Pick one mapping per week and ban yourself from the CMD version.
- Use parameter-discovery aliases
PowerShell lets you type only enough letters to disambiguate:
gci -Rec -Fil *.txt | sort LastWriteTime -des | select -f 10
You did not need to type -Filter or -First in full.
Tab-completion will teach you the shortest unique prefix.
- Keep a “today I learned” text file
Every time you solve something (StackOverflow, colleague, etc.) write the exact line that worked:
2025-09-15 Get newest 10 log files
gci C:\Logs -fil *.log | sort LastWriteTime -des | select -f 10
Review it once a month; you’ll be shocked how much you’ve collected.
- Optional: install PSReadLine goodies
(Already bundled in PowerShell 7+)
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Now ↑ filters history based on what you’ve typed – no more endless ↑↑↑.
- When you must use CMD…
Keep a single batch file called q.bat in %PATH%:
@echo off
rem q.bat Quick dir newest-first
dir /o-d /tw %*
Typing:
q C:\Temp
gives you a sorted listing even from ancient cmd.exe.
Bottom line
- Wrap the ugly command once (function or batch).
- Ask the shell for help instead of the web.
- Log what you learned today.
Do those three and you’ll outgrow the need for cheat sheets within a month.
浙公网安备 33010602011771号