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.


  1. The immediate fix – dir sorted 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

  1. 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.


  1. 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.


  1. 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.


  1. 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.


  1. 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.


  1. 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 ↑↑↑.


  1. 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

  1. Wrap the ugly command once (function or batch).
  2. Ask the shell for help instead of the web.
  3. Log what you learned today.
    Do those three and you’ll outgrow the need for cheat sheets within a month.
posted @ 2025-09-15 15:13  AI健康  阅读(9)  评论(0)    收藏  举报