Windows
Jump to navigation
Jump to search
Contents
- 1 WSL
- 2 Powershell
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
Powershell
environment
$env:Path = "SomeRandomPath";
replaces existing path$env:Path += ";SomeRandomPath"
appends to existing path
heredoc
@" stuf!! morestuff!!! hooray! "@ > stuff.txt
Get-Content -- equivalent of cat
- aliased to
type
Get-ChildItem
ls | sort lastwritetime
- equivalent of POSIXls -lrt
- Amazingly, you CAN'T get human-readable filesize like ls -lh without a bunch of scripting - STUPID!
dir
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'
findstr - equivalent of grep
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
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?
Filesystems
Get-PsDrive -PsProvider FileSystem
equivalent ofdf -h
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
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 which$PSVersionTable.PSVersion
Install-Module <modulename>
Get-Command -module <modulename>
Restart-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