ShareYourGroupShareYourGroupCommands

Guides

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

JobWindows CMDPowerShellLinux and Mac
list a folderdirGet-ChildItem (ls, dir)ls
list with detailsdirGet-ChildItemls -l
include hidden filesdir /aGet-ChildItem -Forcels -a
current foldercdGet-Location (pwd)pwd
change foldercd nameSet-Location name (cd)cd name
make a foldermkdir nameNew-Item -ItemType Directory name (mkdir)mkdir name
remove an empty folderrmdir nameRemove-Item namermdir name
remove a folder and contentsrmdir /s nameRemove-Item -Recurse namerm -r name
copy a filecopy a bCopy-Item a b (cp)cp a b
copy a folderxcopy a b /e /iCopy-Item a b -Recursecp -r a b
move or renamemove a b, ren a bMove-Item a b (mv)mv a b
delete a filedel nameRemove-Item name (rm)rm name
folder treetreetreetree, or find . -type d
find files by namedir /s /b *name*Get-ChildItem -Recurse -Filter *name*find . -name "*name*"

The names in brackets are short aliases that PowerShell accepts.

Text files

JobWindows CMDPowerShellLinux and Mac
show a filetype fileGet-Content file (cat)cat file
page through a filemore fileGet-Content file | moreless file
first lines(none)Get-Content file -TotalCount 10head file
last lines(none)Get-Content file -Tail 10tail file
search inside filesfindstr text fileSelect-String text filegrep text file
count linesfind /c /v "" file(Get-Content file).Countwc -l file
sort linessort fileGet-Content file | Sort-Objectsort file
compare two filesfc a bCompare-Objectdiff a b
print textecho textWrite-Output text (echo)echo text

System and processes

JobWindows CMDPowerShellLinux and Mac
running programstasklistGet-Process (ps)ps aux, top
stop a programtaskkill /im nameStop-Process -Name namekill PID, killall name
who am Iwhoamiwhoamiwhoami
computer namehostnamehostnamehostname
system detailssysteminfoGet-ComputerInfouname -a
disk spacedir (last line)Get-Volumedf -h
folder size(none)Get-ChildItem -Recurse | Measure-Object Length -Sumdu -sh folder
environment variablessetGet-ChildItem Env:env
read a variableecho %NAME%$env:NAMEecho $NAME
clear the screenclsClear-Host (cls, clear)clear
helpcommand /?Get-Help commandman command
shut downshutdown /sStop-Computershutdown now
restartshutdown /rRestart-Computerreboot
run as administratoropen "as administrator"open "as administrator"sudo command

Network

JobWindows CMDLinux and Mac
my addressesipconfigip addr (Linux), ifconfig (Mac)
test a connectionping hostping -c 4 host
trace the routetracert hosttraceroute host
look up a namenslookup namenslookup name, dig name
fetch a web addresscurl URLcurl URL, wget URL
open connectionsnetstat -anss -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

WindowsLinux and Mac
Path separatorbackslash: C:\Users\ashaforward slash: /home/asha
Drivesletters: C:, D:one tree starting at /
Options begin witha slash: /sa dash: -r
Capital letters in namesignoredmatter on Linux; usually ignored on a Mac
Variables%NAME%$NAME
Wildcard for "all files"*.* or **
Line ends in text filestwo charactersone character
Home folder%USERPROFILE%~
Who expands wildcardseach commandthe 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.

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.