Windows

From Colettapedia
Jump to navigation Jump to search

WSL

  • wsl -- bash - when you screw up your shell configuration and you need to start a shell clean
  • wsl.exe --update
  • 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

  1. run diskpart. Wait for DISKPART> prompt
  2. list volume
  3. select volume #
  4. remove all dismount
  5. 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

Resources

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

Equivalent of Pipe stderr to /dev/null

  • -ErrorAction SilentlyContinue

Get-Content -- equivalent of cat

  • aliased to type

Get-ChildItem -- equivalent of ls

  • ls | sort lastwritetime - equivalent of POSIX ls -lrt
    • Amazingly, you CAN'T get human-readable filesize like ls -lh without a bunch of scripting - STUPID!
  • ls -force - equivalent of ls -a
  • dir is an alias for Get-ChildItem = ls
  • dir env: - show all environment variables
    • echo $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" $_ }

foreach - equivalent of xargs

  • ls | foreach { echo $_; echo ""; head -1 $_}
  • ls | foreach { echo $_; echo ""; $( head -1 $_) -split ',' | Sort-Object; echo "==================="} > all_column_names.txt

select-string - PS equivalent of grep

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 drive
  • Get-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

zip equivalent

  • Compress-Archive -Path C:\Reference -DestinationPath C:\Archives\Draft.zip
  • Expand-Archive

Other

  • notepad.exe $PROFILE - edit the equivalent of your .bashrc
    • Can also edit global rcfile $PROFILE.AllUsersAllHosts
    • Profile comments lines begin with hash #
  • get-command = equivalent to which
  • $PSVersionTable.PSVersion
  • Install-Module <modulename>
  • Get-Command -module <modulename>
  • cls - clear screen
  • Restart-Computer and Stop-Computer
  • type is an alias for Get-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