Windows
Jump to navigation
Jump to search
Contents
- 1 WSL
- 2 Non-Powershell Tools
- 3 Powershell
- 3.1 environment
- 3.2 heredoc
- 3.3 Get-Content -- equivalent of cat
- 3.4 Get-ChildItem -- equivalent of ls
- 3.5 select-string - PS equivalent of grep
- 3.6 Copy-Item
- 3.7 Invoke-Expression -- equivalent of sh?
- 3.8 Invoke-Item -- equivalent of MacOS open
- 3.9 Get-FileHash -- equivalent of md5sum
- 3.10 Get-Clipboard / Set-Clipboard -- equivalent of pbcopy/pbpaste
- 3.11 symlinks
- 3.12 Pipes
- 3.13 Get-PsDrive - equivalent of `df -h`
- 3.14 History across sessions
- 3.15 top equivalent
- 3.16 Other
WSL
wsl -- bash
- when you screw up your shell configuration and you need to start a shell clean- DejaVu Sans Mono for Powershell seems to work
- Meslo LG S DZ Regular for Powerline.ttf
- start a tmux everytime
if command -v tmux &> /dev/null && [ -n "$PS1" ] && ! "$TERM" =~ screen && ! "$TERM" =~ tmux && [ -z "$TMUX" ]; then exec tmux fi
Non-Powershell Tools
Eject Volume via command line
- run
diskpart
. Wait forDISKPART>
prompt list volume
select volume #
remove all dismount
- Ctrl-C to exit
findstr - Searches for strings in files
Use spaces to separate multiple search strings unless the argument is prefixed with /C. For example, 'FINDSTR "hello there" x.y' searches for "hello" or "there" in file x.y. 'FINDSTR /C:"hello there" x.y' searches for "hello there" in file x.y.
Powershell
environment
dir env:
show all environment- To assign a new environment var, just use = assignment to
$env:<var_name>
$env:Path = "SomeRandomPath";
replaces existing path$env:Path += ";SomeRandomPath"
appends to existing path
heredoc
- The quote-at and at-quote must be on their own line
@" stuf!! morestuff!!! hooray! "@ > stuff.txt
Get-Content -- equivalent of cat
- aliased to
type
Get-ChildItem -- equivalent of ls
ls | sort lastwritetime
- equivalent of POSIXls -lrt
- Amazingly, you CAN'T get human-readable filesize like ls -lh without a bunch of scripting - STUPID!
ls -force
- equivalent of ls -adir
is an alias forGet-ChildItem
=ls
dir env:
- show all environment variablesecho $Env:Path
- show just one
Find equivalent
gci -r -fi *.jar
Get-ChildItem -Recurse -Filter '*.jar'
ls -r | where{ !$_.PSisContainer } | foreach {select-string -pattern "FIXME" $_ }
select-string - PS equivalent of grep
- Select-String docs
sls -pattern "FIXME" -path "*.py"
- searches in current directory only- non-PS version of this is
findstr
findstr "string" *.txt
- findstr documentation
Copy-Item
Copy-Item -Path "C:\Logfiles" -Destination "C:\Drawings\Logs" -Recurse
Invoke-Expression -- equivalent of sh?
- evaluate this string as a command
Invoke-Item -- equivalent of MacOS open
ii
- like double-clicking on an item
Get-FileHash -- equivalent of md5sum
Get-FileHash <filepath> -Algorithm MD5
md5
on Darwin, btw
Get-Clipboard / Set-Clipboard -- equivalent of pbcopy/pbpaste
- for
Set-Clipboard
can also use-Append
symlinks
New-Item -ItemType SymbolicLink -Path "Link" -Target "Target"
Pipes
| more
- like linux| Out-File "\\server\share\log$($env.computername-Get-Date -f yyyy-MM-dd)-logfile.log" -Force
pipe output of operation to log file| Get-Member -MemberType property
- What are the things you can sort by?
Get-PsDrive - equivalent of `df -h`
Get-PsDrive -PsProvider FileSystem
- shortcut is
gdr
Formatting Storage Devices
- Only works if you're running powershell as admin
get-disk
Get-Disk 2 | Clear-Disk -RemoveData
- Cleans a disk by removing all partition information and un-initializing it, erasing all data on the disk.New-Partition -DiskNumber 1 -UseMaximumSize
get-partition -disknumber 1 | format-volume -filesystem exFAT -newfilesystemlabel ChrisPhone
get-partition -disknumber 1 | set-partition -newdriveletter d
- mount the newly created driveGet-PnpDevice | sort-object -property class | more
- list all plug and play devices
History across sessions
Get-Content (Get-PSReadlineOption).HistorySavePath
top equivalent
Get-Process | Sort-Object -Property "CPU" -Descending | head -30
Other
notepad.exe $PROFILE
- edit the equivalent of your .bashrc- Can also edit global rcfile
$PROFILE.AllUsersAllHosts
- Profile comments lines begin with hash #
- Can also edit global rcfile
get-command
= equivalent to whichExpand-Archive
= equivalent to unzip$PSVersionTable.PSVersion
Install-Module <modulename>
Get-Command -module <modulename>
cls
- clear screenRestart-Computer
andStop-Computer
type
is an alias forGet-Content
=cat
- Ctrl-L clears screen
help
- equivalent of POSIX man"{0} GB" -f ((Get-ChildItem . -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1GB)
- get folder size