コマンドプロンプト、PowerShell、Linuxコマンド比較・対応表 †
コマンドプロンプト(DOS)コマンドに対応するPowerShell, Linuxコマンドの一覧表を記します。
良く使用すると思われるコマンドの一覧になります。
コマンド対応表 †
No | セクション | コマンドプロンプト | PowerShell | Linux |
1 | ファイル・ディレクトリ関連 | dir | Get-ChildItem | ls, dir |
2 | | dir /b | Get-ChildItem -Name | ls -1 |
3 | | dir /ad | Get-ChildItem | Where-Object {$_.Attribute -eq "Directory"} Get-ChildItem | Where-Object { $_.PSIsContainer } | ls -F | grep / |
4 | | dir /od | Get-ChildItem | Sort-Object LastWriteTime | ls -ltr |
5 | | dir /o-d | Get-ChildItem | Sort-Object LastWriteTime -Descending | ls -lt |
6 | | type | Get-Content | cat |
7 | | copy | Copy-Item | cp |
8 | | xcopy robocopy | Copy-Item -Recurse | cp -r |
9 | | del erase | Remove-Item | rm |
10 | | move | Move-Item | mv |
11 | | ren | Rename-Item | mv |
12 | | dir /b /s | Get-ChildItem -Recurse -Name | find . |
13 | | find /c /v "" | (Get-Content 対象ファイル名 | Measure-Object).Count | wc -l |
14 | | cd chdir | Get-Location | pwd |
15 | | mk mkdir | New-Item -ItemType Directory | mkdir |
16 | | cd chdir | Set-Location | cd |
17 | | rd rmdir | Remove-Item | rmdir |
18 | | fc | Compare-Object (Get-Content ファイル名) (Get-Content ファイル名) | diff |
19 | | robocopy | ← | rsync |
20 | | type null > ファイル名 | New-item -ItemType File ファイル名 | touch |
21 | | copy ファイル名 + | (Get-Item ファイル名).LastWriteTime = (Get-Date) | touch |
22 | プロセス | tasklist | Get-Process | ps |
23 | | taskkill | Stop-Process | kill |
24 | | taskkill /im | Get-Process | Where-Object ($_.ProcessName -eq "プロセス名") | % { Stop-Process $_.Id } | killall |
25 | 文字列操作 | findstr | Select-String -CaseSensitive | grep |
26 | | findstr /i | Select-String | grep -i |
27 | | sort | Get-Content ファイル名 | Sort-Object | sort |
28 | | - | Get-Content ファイル名 | Sort-Object | Get-Unique | sort | uniq |
29 | | - | 文字列.Replace("置換前文字列", "置換後文字列")
| tr |
30 | 日付・時刻 | date /t echo %DATE% | Get-Date -Format yyyy/MM/dd | date '+%Y/%m/%d' |
31 | | time /t echo %TIME% | Get-Date -Format hh:mm:ss | date '+%T' |
32 | システム | ver winver systeminfo | findstr /b "OS" | [Environment]::OSVersion | uname -a |
33 | | systeminfo | Get-WMIObject Win32_Processor | Format-List | cat /proc/cpuinfo |
34 | | systeminfo | Get-WMIObject Win32_PhysicalMemory | Format-List | cat /proc/meminfo |
35 | | logman | - | sar |
36 | | logman | - | vmstat |
37 | | logman | - | iostat |
38 | | コマンド /? | Get-Help コマンドレット | man |
39 | | hostname | ← | hostname |
40 | | taskmgr | ← | top |
41 | 環境・シェル関連 | exit | Exit-PSSession | exit |
42 | | set | Get-ChildItem env: | env |
43 | | set | Get-ChildItem env: | printenv |
44 | | echo | Write-Host | echo |
45 | | cls | Clear-Host | clear |
46 | | doskey 別名=コマンド | Set-Alias New-Alias | alias |
47 | | - | Get-History | history |
48 | | %RANDOM% | Get-Random | $RANDOM |
49 | | where | Get-Command | which |
50 | | %ERRORLEVEL% | $lastexitcode | $? |
51 | | - | $PID | $$ |
52 | ユーザ | query user query user /server:ホスト名 | ← | who -u |
53 | | whoami | ← | who am i |
54 | ネットワーク | ipconfig /a | ← | ifconfig -a |
55 | | netstat | ← | netstat |
56 | | arp | ← | arp |
57 | | ping | ← | ping |
58 | | tracert | ← | traceroute |
59 | | nslookup | ← | nslookup |
60 | その他 | NUL | $NULL | /dev/null |
61 | | timeout /t 秒 /nobreak > nul | Start-Sleep | sleep |