Skip to content
DevNursery.com - New Web Developer Docs
GitHub

Shell (Bash/Powershell) Cheatsheet

Typical Terminal Operations: Bash vs. PowerShell

OperationBash CommandPowerShell Command
File Operations
Create a Directorymkdir directory_nameNew-Item -Type Directory directory_name
Create a Filetouch file.txtNew-Item -Type File file.txt
List Files and Directoriesls or ls -lGet-ChildItem or dir
Remove a Filerm file.txtRemove-Item file.txt
Remove a Directoryrm -r directory_nameRemove-Item -Recurse directory_name
Navigation
Change Directorycd path/to/directorySet-Location path\to\directory
Current DirectorypwdGet-Location
Text Processing
Display File Contentscat file.txtGet-Content file.txt
Search for Textgrep pattern file.txtSelect-String pattern file.txt
System Information
System Infouname -aGet-ComputerInfo
Process Management
List Running ProcessespsGet-Process
Kill a Processkill PIDStop-Process -Id PID
Environment Variables
Display Variable Valueecho $VAR_NAMEecho $env:VAR_NAME
Set VariableVAR_NAME=value$env:VAR_NAME = value
Script Execution
Execute Script./script.sh.\script.ps1
Run as Administrator (sudo)sudo commandStart-Process powershell -ArgumentList "command" -Verb RunAs
File Permissions
Change File Permissionschmod 755 file.txtSet-ItemProperty file.txt -Name IsReadOnly $false
List File Permissionsls -l file.txtGet-Acl file.txt
File Manipulation
Copy Filecp source.txt dest.txtCopy-Item source.txt dest.txt
Move Filemv source.txt dest.txtMove-Item source.txt dest.txt
Rename Filemv oldname.txt newname.txtRename-Item oldname.txt newname.txt
File Compression
Create Zip Archivezip -r archive.zip folder/Compress-Archive -Path folder -DestinationPath archive.zip
Extract Zip Archiveunzip archive.zipExpand-Archive -Path archive.zip -DestinationPath folder
Text Editing
Create/Edit Text Filenano file.txtnotepad file.txt
Networking
Check Network Connectionping example.comTest-Connection example.com
User Management
Create Useruseradd usernameNew-LocalUser -Name username
Delete Useruserdel usernameRemove-LocalUser -Name username
Package Management
Update Package Databasesudo apt-get updateUpdate-Package
Install Packagesudo apt-get install pkgInstall-Package pkg
Remove Packagesudo apt-get remove pkgUninstall-Package pkg
System Services
Start Servicesudo systemctl start serviceStart-Service service
Stop Servicesudo systemctl stop serviceStop-Service service
Environment Setup
Set Environment Variableexport VAR_NAME=value$env:VAR_NAME = "value"
SSH
SSH to Remote Hostssh user@hostnameEnter-PSSession -ComputerName hostname -Credential user
File Search
Find Files by Namefind /path -name "pattern"Get-ChildItem -Path /path -Filter pattern
Find Files by Typefind /path -type fGet-ChildItem -Path /path -File
Find Directoriesfind /path -type dGet-ChildItem -Path /path -Directory
File Permissions
Change Ownershipchown user:group fileSet-Acl file -Owner user
File Comparison
Compare Two Filesdiff file1.txt file2.txtCompare-Object -ReferenceObject (Get-Content file1.txt) -DifferenceObject (Get-Content file2.txt)
Text Manipulation
Count Lines in a Filewc -l file.txt`Get-Content file.txt
File Permissions
Change File Permissionschmod 644 file.txt`Set-Acl file.txt -AclObject (Get-Acl file.txt) -PermissionSet “Read”
File Size
Get File Sizestat -c %s file.txt(Get-Item file.txt).Length
Time and Date
Display Current DatedateGet-Date
Package Management
List Installed Packagesdpkg -lGet-Package
System Information
List System InformationlscpuGet-WmiObject -Class Win32_ComputerSystem
Network Configuration
Show Network InterfacesifconfigGet-NetAdapter
Service Management
List Running Servicessystemctl list-units --type=serviceGet-Service
User Management
Change User Passwordpasswd usernameSet-LocalUser -Name username -Password (ConvertTo-SecureString -AsPlainText "newpassword" -Force)
File Archiving
Create Tar Archivetar -cvf archive.tar folder/Compress-Archive -Path folder -DestinationPath archive.tar
Extract Tar Archivetar -xvf archive.tarExpand-Archive -Path archive.tar -DestinationPath folder
Clipboard Operations
Copy to Clipboard`echo “text”xclip -sel clip`
Paste from Clipboardxclip -o -sel clipGet-Clipboard
File Permissions
Check File Permissionsls -l file.txtGet-Acl file.txt