tail -f app.log or Get-ChildItem -Recurse, and see the other shell’s version, or browse 119 everyday tasks: files, text, processes, services, networking and scripting. Every PowerShell command here was checked in PowerShell 7, and the ones that only work on Windows are marked.Click any command to copy it. Windows only needs Windows; everything else also works in PowerShell 7 on Linux and macOS. PowerShell 7+ isn’t in Windows PowerShell 5.1.
| Task | BashLinux, macOS, WSL | PowerShellWindows; PowerShell 7 also on Linux and macOS |
|---|---|---|
| Files and folders | ||
| List files | lsls <dir> | Get-ChildItemAliases dir and gci, and ls on Windows.Get-ChildItem <dir> |
| List files, including hidden ones | ls -la | Get-ChildItem -ForceAliases dir and gci, and ls on Windows. -Force adds hidden files. |
| List everything under a folder | ls -R <dir>find <dir> | Get-ChildItem <dir> -Recurse -Force-Force includes hidden files and folders, as ls -R and find do. |
| Find files by name | find <dir> -name '*.log' | Get-ChildItem <dir> -Recurse -Force -Filter *.log-Filter is faster than -Include. Matching is case-insensitive on Windows. -Force includes hidden files and folders, as find does. |
| Find files bigger than 100 MB | find <dir> -type f -size +100M | Get-ChildItem <dir> -Recurse -File -Force | Where-Object Length -gt 100MBPowerShell understands KB, MB, GB and TB in numbers. -Force includes hidden files and folders, as find does. |
| Find files changed in the last day | find <dir> -type f -mtime -1 | Get-ChildItem <dir> -Recurse -File -Force | Where-Object LastWriteTime -gt (Get-Date).AddDays(-1)-Force includes hidden files and folders, as find does. |
| Show the current folder | pwd | Get-LocationAlias pwd. |
| Change folder | cd <dir> | Set-Location <dir>Alias cd. cd - goes back in PowerShell 6.2 and later too. |
| Make a folder, with any missing parents | mkdir -p <dir> | New-Item -ItemType Directory -Force -Path <dir>Creates parent folders, and -Force means no error if it already exists. |
| Create an empty file (or update its time) | touch <file> | if (Test-Path <file>) { (Get-Item <file>).LastWriteTime = Get-Date } else { New-Item -ItemType File -Path <file> }Don't use New-Item -Force on an existing file: it empties it. |
| Copy a file | cp <file> <dest> | Copy-Item <file> <dest>Aliases copy and cpi, and cp on Windows. |
| Copy a folder and everything in it | cp -r <dir> <dest> | Copy-Item <dir> <dest> -Recurse |
| Move or rename | mv <file> <dest> | Move-Item <file> <dest>To rename in place, Rename-Item <file> newname.txt also works. |
| Delete a file | rm <file> | Remove-Item <file>Aliases del and ri, and rm on Windows. |
| Delete a folder and everything in it | rm -rf <dir>No undo, no prompt. | Remove-Item <dir> -Recurse -ForceNo undo. -Force also removes hidden and read-only files. |
| Check whether a file exists | [ -e <file> ] && echo yes || echo noUse -f for a regular file, -d for a folder. | Test-Path <file>Returns True or False. Add -PathType Leaf for a file or -PathType Container for a folder. |
| Size of a file | stat -c %s <file>In bytes. On macOS: stat -f %z <file>. For a readable size: du -h <file>. | (Get-Item <file>).LengthIn bytes. |
| Total size of a folder | du -sh <dir>Space used on disk; add --apparent-size for the total of the file sizes, which is what PowerShell adds up. | (Get-ChildItem <dir> -Recurse -File -Force | Measure-Object Length -Sum).Sum / 1MBIn MB. |
| Free disk space | df -h | Get-PSDrive -PSProvider FileSystemUsed and free space per drive.Get-VolumeWindows only |
| Make a symbolic link | ln -s <target> <link> | New-Item -ItemType SymbolicLink -Path <link> -Target <target>On Windows this needs an administrator prompt or Developer Mode. |
| SHA-256 checksum of a file | sha256sum <file>On macOS: shasum -a 256 <file>. | Get-FileHash <file>SHA-256 by default, shown in capitals. Add -Algorithm MD5 or -Algorithm SHA1 for others. |
| Zip a folder | zip -r <archive>.zip <dir> | Compress-Archive -Path <dir> -DestinationPath <archive>.zipLeaves out hidden files and folders (like .env), which zip -r includes. |
| Unzip a file | unzip <archive>.zip -d <dir> | Expand-Archive <archive>.zip -DestinationPath <dir> |
| Make a .tar.gz archive | tar -czf <archive>.tar.gz <dir> | tar -czf <archive>.tar.gz <dir>The same command: tar.exe ships with Windows 10 (1803) and later. |
| Show who can access a file | ls -l <file> | Get-Acl <file> | Format-ListWindows onlyWindows uses access lists, not owner/group/other bits. On Linux and macOS, PowerShell 7.1+ shows a UnixMode column in Get-ChildItem instead.icacls <file>Windows onlyThe classic Windows tool, often easier to read. |
| Reading and searching text | ||
| Show a file | cat <file> | Get-Content <file>Aliases gc and type, and cat on Windows. |
| First 10 lines | head -n 10 <file> | Get-Content <file> -TotalCount 10-Head is another name for -TotalCount. |
| Last 10 lines | tail -n 10 <file> | Get-Content <file> -Tail 10 |
| Follow a log as it grows | tail -f <file> | Get-Content <file> -Wait -Tail 10Ctrl+C stops it. |
| Count lines | wc -l <file>Counts newline characters, so a last line without one isn't counted. | (Get-Content <file>).CountCounts lines, including a last line with no newline at the end. |
| Find lines containing text | grep '<text>' <file>Case-sensitive. | Select-String -Pattern '<text>' -Path <file> -CaseSensitiveSelect-String ignores case unless you add -CaseSensitive, the opposite of grep. Each match is shown as file:line:text. The pattern is a regex; add -SimpleMatch for plain text. Alias sls. |
| Find text, ignoring case | grep -i '<text>' <file> | Select-String -Pattern '<text>' -Path <file> |
| Search every file under a folder | grep -rn '<text>' <dir> | Get-ChildItem <dir> -Recurse -File -Force | Select-String -Pattern '<text>' -CaseSensitivePrints file:line:text, like grep -rn. -Force includes hidden files, as grep -r does. |
| Lines that don't contain text | grep -v '<text>' <file> | Select-String -Pattern '<text>' -Path <file> -NotMatch -CaseSensitive |
| Show lines around each match | grep -C 2 '<text>' <file> | Select-String -Pattern '<text>' -Path <file> -Context 2 -CaseSensitive |
| List only the files that contain text | grep -rl '<text>' <dir> | Get-ChildItem <dir> -Recurse -File -Force | Select-String -Pattern '<text>' -List -CaseSensitive | Select-Object -ExpandProperty Path-Force includes hidden files, as grep -r does. |
| Count matching lines | grep -c '<text>' <file> | (Select-String -Pattern '<text>' -Path <file> -CaseSensitive).Count |
| Replace text in a file | sed -i 's/<old>/<new>/g' <file>On macOS: sed -i '' 's/<old>/<new>/g' <file>. | (Get-Content <file>) -replace '<old>', '<new>' | Set-Content <file>-replace uses regex. The brackets read the whole file before writing. Windows PowerShell 5.1 saves in the system code page unless you add -Encoding utf8. |
| Sort lines | sort <file>The order depends on your locale; LC_ALL=C sort puts capitals first. | Get-Content <file> | Sort-ObjectIgnores case when sorting; add -CaseSensitive to sort capitals separately. |
| Sort and remove duplicate lines | sort -u <file> | Get-Content <file> | Sort-Object -Unique -CaseSensitiveWithout -CaseSensitive, lines that differ only in case count as duplicates. |
| Count how often each line appears | sort <file> | uniq -c | sort -rn | Get-Content <file> | Group-Object -CaseSensitive | Sort-Object Count -Descending | Select-Object Count, Name |
| Print one column (space-separated) | awk '{print $2}' <file> | Get-Content <file> | ForEach-Object { ($_.Trim() -split '\s+')[1] }PowerShell counts from 0, so [1] is the second column. |
| Print one field (comma-separated) | cut -d, -f2 <file>Lines with no comma are printed whole; add -s to skip them, like the PowerShell version does. | Get-Content <file> | ForEach-Object { ($_ -split ',')[1] }For real CSV files with quotes, use Import-Csv. |
| Read a value from JSON | jq -r '.name' <file> | (Get-Content <file> -Raw | ConvertFrom-Json).name |
| Show a CSV file as a table | column -s, -t < <file> | Import-Csv <file> | Format-Table |
| Write text to a file (replacing it) | echo '<text>' > <file> | Set-Content -Path <file> -Value '<text>'In Windows PowerShell 5.1, > writes UTF-16; Set-Content writes the system code page. PowerShell 7 writes UTF-8 for both. |
| Add a line to the end of a file | echo '<text>' >> <file> | Add-Content -Path <file> -Value '<text>' |
| Compare two files | diff <file1> <file2> | Compare-Object (Get-Content <file1>) (Get-Content <file2>) -CaseSensitive<= marks lines only in the first file, => lines only in the second. Without -CaseSensitive, lines that differ only in case count as the same. |
| Processes and commands | ||
| List running processes | ps aux | Get-ProcessAlias gps, and ps on Windows. |
| Find a process by name | pgrep -a <name> | Get-Process -Name <name>Give the name without .exe. Wildcards work: -Name *sql*. |
| Processes using the most CPU | ps aux --sort=-%cpu | head | Get-Process | Sort-Object CPU -Descending | Select-Object -First 10CPU is total processor seconds since the process started, not the current percentage. |
| Stop a process by ID | kill <pid> | Stop-Process -Id <pid>Ends the process at once, like kill -9: it gets no chance to clean up. On Linux and macOS, typing kill <pid> in PowerShell runs the real kill, which asks it to stop. |
| Force-stop a process | kill -9 <pid> | Stop-Process -Id <pid> -Force-Force only skips the question PowerShell asks before stopping another user’s process; without it the stop is just as sudden. |
| Stop processes by name | pkill <name> | Stop-Process -Name <name> |
| Run a command in the background | <cmd> & | Start-Job { <cmd> }Receive-Job collects the output later.<cmd> &PowerShell 7+PowerShell 7 also has & at the end, which starts a job. |
| Wait a few seconds | sleep 5 | Start-Sleep -Seconds 5 |
| Time how long a command takes | time <cmd> | Measure-Command { <cmd> }The command's own output is hidden; only the time is shown. |
| Find where a command lives | command -v <name>which <name> works too. | Get-Command <name>Shows cmdlets, functions, aliases and programs. Add | Select-Object -ExpandProperty Source for the path. |
| Run as administrator | sudo <cmd> | Start-Process pwsh -Verb RunAsWindows onlyOpens an elevated PowerShell window. With only Windows PowerShell 5.1, use powershell instead of pwsh. Windows 11 24H2 and later also have a sudo command, once turned on in Settings. |
| Services (systemd vs Windows services) | ||
| Is a service running? | systemctl status <svc> | Get-Service <svc>Windows only |
| Start a service | sudo systemctl start <svc> | Start-Service <svc>Windows onlyRun PowerShell as administrator. |
| Stop a service | sudo systemctl stop <svc> | Stop-Service <svc>Windows onlyRun PowerShell as administrator. |
| Restart a service | sudo systemctl restart <svc> | Restart-Service <svc>Windows onlyRun PowerShell as administrator. |
| Start a service at boot | sudo systemctl enable <svc> | Set-Service <svc> -StartupType AutomaticWindows onlyRun PowerShell as administrator. |
| List running services | systemctl list-units --type=service --state=running | Get-Service | Where-Object Status -eq RunningWindows only |
| Recent log messages | journalctl -u <svc> -n 50 | Get-WinEvent -LogName System -MaxEvents 50Windows onlyWindows services log to the Event Log rather than a per-service journal. |
| Networking | ||
| Ping a host 4 times | ping -c 4 <host> | Test-Connection <host> -Count 4ping <host> also works on Windows, which pings 4 times by default. |
| Check whether a TCP port is open | nc -zv <host> <port> | Test-NetConnection <host> -Port <port>Windows onlyLook for TcpTestSucceeded : True.Test-Connection <host> -TcpPort <port>PowerShell 7+Returns True or False. |
| Look up a host name in DNS | dig +short <host>nslookup <host> works too. | Resolve-DnsName <host>Windows only[System.Net.Dns]::GetHostAddresses('<host>')Works on every system. |
| Download a file | curl -LO <url>wget <url> works too. | Invoke-WebRequest <url> -OutFile <file>In Windows PowerShell 5.1, add -UseBasicParsing on servers without Internet Explorer set up. There, curl and wget are aliases for this cmdlet, not the real programs. |
| Call a JSON API | curl -s <url> | jq | Invoke-RestMethod <url>The JSON comes back as objects, so (Invoke-RestMethod <url>).name reads a field. |
| Show only the HTTP headers | curl -I <url> | (Invoke-WebRequest <url> -Method Head).Headers |
| Show IP addresses | ip -br addr | Get-NetIPAddress | Format-Table InterfaceAlias, IPAddress, PrefixLengthWindows onlyipconfigWindows onlyThe classic Windows command. |
| Show listening ports | sudo ss -tulpn | Get-NetTCPConnection -State ListenWindows onlyOwningProcess is the process ID. netstat -ano is the classic tool. |
| Show the routing table | ip route | Get-NetRouteWindows onlyroute print is the classic tool. |
| Trace the route to a host | traceroute <host> | Test-NetConnection <host> -TraceRouteWindows onlyTest-Connection <host> -TraceroutePowerShell 7+ |
| Copy a file to a server | scp <file> <user>@<host>:<path> | scp <file> <user>@<host>:<path>The same command: the OpenSSH client is built into Windows 10 (1809) and later. |
| System and environment | ||
| Computer name | hostname | [Environment]::MachineNamehostname works too. |
| Current user name | whoami | [Environment]::UserNamewhoami works too, and on Windows it includes the domain. |
| How long since the last restart | uptime | Get-UptimePowerShell 7+(Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTimeWindows onlyFor Windows PowerShell 5.1. |
| Operating system version | cat /etc/os-release | $PSVersionTable.OSPowerShell 7+Get-ComputerInfo -Property OsName, OsVersionWindows only |
| Read an environment variable | echo "$HOME" | $env:HOMEOn Windows the home folder is in $env:USERPROFILE. $HOME works everywhere. |
| Set an environment variable for this session | export NAME=value | $env:NAME = 'value' |
| Set an environment variable permanently | echo 'export NAME=value' >> ~/.bashrcTakes effect in new shells. | [Environment]::SetEnvironmentVariable('NAME', 'value', 'User')Windows onlyTakes effect in new windows. |
| List all environment variables | env | Get-ChildItem Env: |
| Add a folder to PATH for this session | export PATH="$PATH:/opt/tools/bin" | $env:PATH += [IO.Path]::PathSeparator + 'C:\tools'PathSeparator is ; on Windows and : elsewhere. |
| Current date and time | date | Get-Date |
| Date as 2026-11-12 | date +%Y-%m-%d | Get-Date -Format yyyy-MM-ddFormat letters are case-sensitive: MM is month, mm is minutes. |
| Unix timestamp | date +%s | [DateTimeOffset]::UtcNow.ToUnixTimeSeconds() |
| Command history | history | Get-HistoryThis session only.Get-Content (Get-PSReadLineOption).HistorySavePathEverything saved from earlier sessions. |
| Clear the screen | clear | Clear-HostAlias cls, and clear on Windows. |
| Restart the computer | sudo reboot | Restart-Computer |
| Shut down now | sudo shutdown now | Stop-Computer |
| Help for a command | man <cmd> | Get-Help <cmd> -FullRun Update-Help once first, or add -Online to read it in a browser. |
| Make a shortcut for a command | alias ll='ls -la' | function ll { Get-ChildItem -Force @args }Set-Alias can't include options, so use a function. Put it in your $PROFILE file to keep it. |
| Scripting | ||
| Set a variable | name='value'No spaces around =. | $name = 'value' |
| Put a variable inside text | echo "Hello $name" | "Hello $name"Double quotes expand variables in both shells; single quotes don't. For a property, use "$($user.Name)". |
| If a file exists | if [ -f <file> ]; then echo found; fi | if (Test-Path <file> -PathType Leaf) { 'found' } |
| Compare numbers | if [ "$n" -gt 5 ]; then echo big; fi | if ($n -gt 5) { 'big' }Both shells use -gt, -lt, -ge, -le, -eq and -ne. In PowerShell they also compare text. |
| Compare text | if [ "$a" = "yes" ]; then echo ok; fi | if ($a -eq 'yes') { 'ok' }-eq ignores case in PowerShell; use -ceq to match case. |
| Loop over files | for f in *.log; do echo "$f"; done | foreach ($f in Get-ChildItem *.log) { $f.Name } |
| Loop over numbers | for i in {1..5}; do echo "$i"; done | foreach ($i in 1..5) { $i } |
| Read a file line by line | while IFS= read -r line; do echo "$line"; done < <file> | foreach ($line in Get-Content <file>) { $line } |
| Write a function | greet() { echo "Hi $1"; } | function Greet($Name) { "Hi $Name" }Call it as Greet Alice, without brackets or commas. |
| Script arguments | echo "First: $1, all: $*" | "First: $($args[0]), all: $args"Or declare them: param($Path, $Count = 1) at the top of the script. |
| Exit code of the last command | echo $? | $LASTEXITCODEFor programs like git or ping. $? is True or False for the last command of any kind. |
| Stop the script on the first error | set -euo pipefail | $ErrorActionPreference = 'Stop'Covers cmdlets. In PowerShell 7.4 and later, also set $PSNativeCommandUseErrorActionPreference = $true to stop when a program like git fails. |
| Throw away all output | <cmd> > /dev/null 2>&1 | <cmd> *> $null| Out-Null hides normal output only. |
| Send errors to a file | <cmd> 2> errors.txt | <cmd> 2> errors.txtThe same syntax. |
| Save a command's output in a variable | now=$(date) | $now = Get-DatePowerShell keeps the object, so $now.Year works. |
| Ask the user for input | read -rp 'Name: ' name | $name = Read-Host 'Name' |
| Run something if a command fails | <cmd> || echo failed | try { <cmd> } catch { 'failed' }For cmdlets, add -ErrorAction Stop so errors reach catch. A program that fails (exit code not 0) doesn’t reach catch; check if ($LASTEXITCODE -ne 0) { … } after it. PowerShell 7 also has ||, which works for both. |
| Run a script | ./script.shNeeds chmod +x script.sh once, or run bash script.sh. | .\script.ps1If Windows blocks it, run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned once. |
| Scheduling, users and software | ||
| Run a script every day at 2 AM | 0 2 * * * /opt/scripts/backup.shAdd this line with crontab -e. | Register-ScheduledTask -TaskName Backup -Trigger (New-ScheduledTaskTrigger -Daily -At 2am) -Action (New-ScheduledTaskAction -Execute 'pwsh' -Argument '-File C:\scripts\backup.ps1') -User SYSTEMWindows onlyRun this in an administrator window. -User SYSTEM runs it whether or not anyone is signed in, as the local system account; without it, the task runs only while you are signed in. With only Windows PowerShell 5.1, use powershell instead of pwsh. |
| List scheduled jobs | crontab -l | Get-ScheduledTask | Where-Object State -ne DisabledWindows only |
| List local users | getent passwd | Get-LocalUserWindows only |
| Groups the current user belongs to | id | whoami /groupsWindows only |
| Add a local user | sudo useradd -m <user>Then sudo passwd <user>. The User & sudo Builder has the full set of options. | New-LocalUser -Name <user> -Password (Read-Host -AsSecureString)Windows onlyRun as administrator. Prompts for the password. |
| Install a program | sudo apt install <pkg>dnf on Fedora and RHEL, pacman on Arch: see the Package Manager Translator. | winget install <pkg>Windows onlywinget is built into Windows 10 and 11. See the Package Manager Translator for the rest. |
No tasks match that filter.
Get-Process hands over process objects, so you pick fields by name (Where-Object CPU -gt 10) instead of cutting columns.-eq, -like, -match, Select-String, Sort-Object and Group-Object all ignore case unless you use -ceq, -cmatch or -CaseSensitive. Bash and grep are case-sensitive.ls, cat, rm, cp and ps run PowerShell cmdlets with different options, so ls -la fails there. PowerShell on Linux and macOS leaves those names to the real programs. In Windows PowerShell 5.1, curl and wget are aliases for Invoke-WebRequest; PowerShell 7 runs the real curl.exe.`n for a new line and ` at the end of a line to continue it, where Bash uses a backslash. Backslashes are just path separators.-eq, -ne, -gt and -lt, but PowerShell uses them everywhere, not only inside [ ]. > is always redirection, never "greater than".powershell.exe) ships with Windows. PowerShell 7 (pwsh) is a separate install that also runs on Linux and macOS. $PSVersionTable.PSVersion tells you which one you're in.> and the local code page with Set-Content, which confuses Linux tools. PowerShell 7 writes UTF-8 without a BOM everywhere.$LASTEXITCODE holds the exit code of the last program (git, ping, curl.exe). $? is only True or False.Paste a command you know, like tail -f app.log or Get-ChildItem -Recurse, and see the other shell’s version with your file names filled in, or browse 119 everyday tasks. Every PowerShell command was checked in PowerShell 7, and the ones that only work on Windows are marked.
Select-String, or sls for short: Select-String -Pattern 'error' -Path app.log. Unlike grep it ignores case by default, so add -CaseSensitive for the same results. To search the output of a cmdlet, turn it into text first: Get-Process | Out-String -Stream | Select-String chrome.
Get-Content app.log -Wait -Tail 10 prints the last 10 lines and then each new line as it’s written. Press Ctrl+C to stop.
Get-Command git (alias gcm) finds cmdlets, functions, aliases and programs. (Get-Command git).Source prints just the path to the program.
On Windows, ls is an alias for Get-ChildItem, which has different options. Use Get-ChildItem -Force to include hidden files. PowerShell on Linux and macOS doesn’t define that alias, so there ls -la runs the real ls.
Yes. PowerShell 7 (pwsh) runs on Linux and macOS as well as Windows. Commands that manage Windows itself, such as services, the registry, event logs and Get-NetIPAddress, don’t exist there; the table marks them Windows only.
Related tools: Bash Snippet Builder · Package Manager Translator · All tools A–Z
Most tools run entirely in your browser. Tools marked 📡 contact outside services, as listed in the Privacy Policy. Review commands before you run them; see the Terms.