Skip to main content
  1. Resources/

CLI_Commands

3 mins

Working in different terminal emulators on different computers can be frustrating if you don’t spend a lot of time in each of them. In my personal life I primarily use Bash on Linux, while in my professional life I work on Windows with CMD & Powershell.

To save myself aggravation I put together a quick reference table showing common Bash commands with their equivalent in CMD & Powershell.

Below is that reference table, feel free to copy or add commands in the comments that you have found helpful in your workflow.

DescriptionBash SyntaxCMD SyntaxPowerShell Syntax
Print working directorypwdcdGet-Location
List directory contentsls or ls -l for detailsdirGet-ChildItem
Change directorycd /pathcd \pathSet-Location /path
Copy filecp source destcopy source destCopy-Item source dest
Move or rename filemv source destmove source destMove-Item source dest
Delete filerm filedel fileRemove-Item file
Create directorymkdir dirmkdir dir or md dirNew-Item -ItemType Directory dir
Remove empty directoryrmdir dirrmdir dir or rd dirRemove-Item dir
Remove directory with contentsrm -r dirrmdir /s dir or rd /s dirRemove-Item -Recurse dir
View file contentscat filetype fileGet-Content file
Search for pattern in filegrep "pattern" filefindstr "pattern" fileSelect-String "pattern" file
Pipe outputcommand1 | command2command1 | command2command1 | command2
Redirect output (overwrite)command > filecommand > filecommand | Out-File file
Redirect output (append)command >> filecommand >> filecommand | Out-File -Append file
Echo textecho "text"echo textWrite-Output "text"
Create empty filetouch filetype nul > fileNew-Item file
Find filesfind /path -name "*.txt"dir /s /b *.txtGet-ChildItem -Recurse -Filter "*.txt"
List processespstasklistGet-Process
Kill process by IDkill PIDtaskkill /PID PIDStop-Process -Id PID
Ping a hostping hostping hostTest-Connection host
View last lines of filetail -n 10 filemore + (line count - 10) fileGet-Content -Tail 10 file
Count lines/words/characterswc filefind /c /v "" file (lines only)Get-Content file | Measure-Object -Line -Word -Character
Sort file contentssort filesort fileGet-Content file | Sort-Object
Get unique linesuniq filesort file | findstr /x /v /b /e /g:file (complex)Get-Content file | Select-Object -Unique
Compare filesdiff file1 file2fc file1 file2Compare-Object (Get-Content file1) (Get-Content file2)
Download file from URLwget url -O filecurl url -o file (if curl available)Invoke-WebRequest -Uri url -OutFile file
Set environment variableexport VAR=valueset VAR=value$env:VAR = "value"
Get environment variableecho $VARecho %VAR%$env:VAR
Get command helpman commandcommand /?Get-Help command
Display usernamewhoamiwhoamiwhoami
System informationuname -asysteminfoGet-ComputerInfo
Compress files (tar.gz)tar -czf archive.tar.gz filesNo built-in, use third-partyCompress-Archive -Path files -DestinationPath archive.zip (zip)
Extract archivetar -xzf archive.tar.gzNo built-in, use third-partyExpand-Archive -Path archive.zip (zip)