Windows and Linux commands side by side
Instructions on the internet are usually written for one system. If you know the command on Windows and need it on Linux, or the reverse, this page is the translation table. The Mac uses the Linux column for nearly everything.
Files and folders
| Job | Windows CMD | PowerShell | Linux and Mac |
|---|---|---|---|
| list a folder | dir | Get-ChildItem (ls, dir) | ls |
| list with details | dir | Get-ChildItem | ls -l |
| include hidden files | dir /a | Get-ChildItem -Force | ls -a |
| current folder | cd | Get-Location (pwd) | pwd |
| change folder | cd name | Set-Location name (cd) | cd name |
| make a folder | mkdir name | New-Item -ItemType Directory name (mkdir) | mkdir name |
| remove an empty folder | rmdir name | Remove-Item name | rmdir name |
| remove a folder and contents | rmdir /s name | Remove-Item -Recurse name | rm -r name |
| copy a file | copy a b | Copy-Item a b (cp) | cp a b |
| copy a folder | xcopy a b /e /i | Copy-Item a b -Recurse | cp -r a b |
| move or rename | move a b, ren a b | Move-Item a b (mv) | mv a b |
| delete a file | del name | Remove-Item name (rm) | rm name |
| folder tree | tree | tree | tree, or find . -type d |
| find files by name | dir /s /b *name* | Get-ChildItem -Recurse -Filter *name* | find . -name "*name*" |
The names in brackets are short aliases that PowerShell accepts.
Text files
| Job | Windows CMD | PowerShell | Linux and Mac |
|---|---|---|---|
| show a file | type file | Get-Content file (cat) | cat file |
| page through a file | more file | Get-Content file | more | less file |
| first lines | (none) | Get-Content file -TotalCount 10 | head file |
| last lines | (none) | Get-Content file -Tail 10 | tail file |
| search inside files | findstr text file | Select-String text file | grep text file |
| count lines | find /c /v "" file | (Get-Content file).Count | wc -l file |
| sort lines | sort file | Get-Content file | Sort-Object | sort file |
| compare two files | fc a b | Compare-Object | diff a b |
| print text | echo text | Write-Output text (echo) | echo text |
System and processes
| Job | Windows CMD | PowerShell | Linux and Mac |
|---|---|---|---|
| running programs | tasklist | Get-Process (ps) | ps aux, top |
| stop a program | taskkill /im name | Stop-Process -Name name | kill PID, killall name |
| who am I | whoami | whoami | whoami |
| computer name | hostname | hostname | hostname |
| system details | systeminfo | Get-ComputerInfo | uname -a |
| disk space | dir (last line) | Get-Volume | df -h |
| folder size | (none) | Get-ChildItem -Recurse | Measure-Object Length -Sum | du -sh folder |
| environment variables | set | Get-ChildItem Env: | env |
| read a variable | echo %NAME% | $env:NAME | echo $NAME |
| clear the screen | cls | Clear-Host (cls, clear) | clear |
| help | command /? | Get-Help command | man command |
| shut down | shutdown /s | Stop-Computer | shutdown now |
| restart | shutdown /r | Restart-Computer | reboot |
| run as administrator | open "as administrator" | open "as administrator" | sudo command |
Network
| Job | Windows CMD | Linux and Mac |
|---|---|---|
| my addresses | ipconfig | ip addr (Linux), ifconfig (Mac) |
| test a connection | ping host | ping -c 4 host |
| trace the route | tracert host | traceroute host |
| look up a name | nslookup name | nslookup name, dig name |
| fetch a web address | curl URL | curl URL, wget URL |
| open connections | netstat -an | ss -tuln (Linux), netstat -an (Mac) |
curl and tar are included with Windows 10 and 11, so those two work the same on all three systems.
The differences that catch people out
| Windows | Linux and Mac | |
|---|---|---|
| Path separator | backslash: C:\Users\asha | forward slash: /home/asha |
| Drives | letters: C:, D: | one tree starting at / |
| Options begin with | a slash: /s | a dash: -r |
| Capital letters in names | ignored | matter on Linux; usually ignored on a Mac |
| Variables | %NAME% | $NAME |
| Wildcard for "all files" | *.* or * | * |
| Line ends in text files | two characters | one character |
| Home folder | %USERPROFILE% | ~ |
| Who expands wildcards | each command | the shell, before the command runs |
The last line explains some surprises. On Linux, rm *.txt is turned into rm a.txt b.txt by the shell before rm starts. On Windows, del *.txt passes the pattern to del, which does its own matching.
Text files moved from Windows to Linux sometimes cause odd errors in scripts, because of the different line endings. Editors can save in either style, and the tool dos2unix converts a file.
Running Linux commands on Windows
There are three common ways.
- Windows Subsystem for Linux (WSL) runs a real Linux system inside Windows. Open a Command Prompt as administrator and run
wsl --install. - Git Bash, which comes with Git for Windows, provides the Bash shell and the common Linux tools, working on your Windows files. The Linux examples on this site were run with it.
- PowerShell aliases make
ls,cat,cp,mv,rmandpwdwork, though with PowerShell's options, not Linux's.
Which column should I learn?
Learn the one for the system in front of you. The ideas, listing, moving, copying, searching, piping, are the same in all three. Once they are familiar in one, the others are a matter of looking up a name in the table above.
This is an independent learning site. It is not connected with Microsoft, Apple or any Linux distribution. Windows, macOS and other names belong to their owners. Try commands first in a practice folder, never on files you cannot afford to lose.