PS C:\> wsl --install
PS C:\> wsl --set-default-version 2
https://learn.microsoft.com/en-us/windows/wsl/compare-versions#whats-new-in-wsl-2
PS C:\> wsl --list
PS C:\> wsl --list --running ## Only running Distros
PS C:\> wsl --list --verbose ## Verbose mode
PS C:\> wsl --set-version <distro-name> 2
PS C:\> wsl ls ~
PS C:\> wsl cat /etc/os-release
> wsl -d <distro-name> ls ~
> wsl -d <distro-name> cat /etc/os-release
PS C:\> wsl whoami
PS C:\> wsl -u root whoami
PS C:\> wsl --terminate <distro-name>
PS C:\> wsl --shutdown
https://learn.microsoft.com/pt-br/windows/wsl/wsl-config
[ .wslconfig ] [ wsl.conf ]
settings.json
CTRL + SHIFT + SPACEBAR
CTRL + SHIFT + T
CTRL + TAB
CTRL + SHIFT + 1
CTRL + SHIFT + 2
CTRL + ALT + 1
CTRL + ALT + 2
CTRL + SHIFT + W
CTRL + ,
ALT + SHIFT + -
ALT + SHIFT + +
ALT + SHIFT + D
CTRL + SHIFT + P
ALT + cursor Up ALT + cursor Down ALT + cursor Left ALT + cursor Right
ALT + SHIFT + cursor Up ALT + SHIFT + cursor Down ALT + SHIFT + cursor Left ALT + SHIFT + cursor Right
\\wsl$
PS C:\> Get-Content '\\wsl$\Ubuntu\home\matheus\hello.txt'
$env:SystemRoot = [ C:\Windows ]
PS C:\> Get-Childitem $env:SystemRoot
PS C:\> Get-Childitem $env:SystemRoot | ForEach-Object { $_.Name.Substring(0,1).ToUpper() }
PS C:\> Get-Childitem $env:SystemRoot | ForEach-Object { $_.Name.Substring(0,1).ToUpper() } | wsl sort | wsl uniq -c
PS C:\> Get-Childitem $env:SystemRoot | ForEach-Object { $_.Name.Substring(0,1).ToUpper() } | wsl bash -c "sort | uniq -c"
PS C:\> wsl ls /usr/bin
PS C:\> wsl bash -c "ls /usr/bin | cut -c1"
PS C:\> wsl bash -c "ls /usr/bin | cut -c1-1" | Group-Object
## Accessing Windows files from Linux (WSL2)
NOTE: "Although the Linux side treats the file system as case-sensitive, the underlying Windows file system is still case-insensitive and it is important to keep this in mind."
```bash
$ cat /mnt/c/Users/mathe/lab/wsl2-book/hello.txt
$ /mnt/c/Windows/System32/calc.exe
$ notepad.exe "c:\\Users\\mathe\\lab\\wsl2-book\\hello.txt"
$ echo $PATH
$ powershell.exe -C "Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System"
echo "Matheus" | powershell.exe -noprofile -c 'Write-Host "Hello $input"'
$ ln -s /mnt/c/<custom-path>/ .
$ ln -s /mnt/c/Users/mathe/Downloads/ .
$ ln -s /mnt/c/Users/mathe/lab/ .
$ ln -s /mnt/c/Users/mathe/lab/vagrant/ .
$ touch /home/matheus/teste.txt
$ sudo apt install wslu
$ wslview teste.txt
$ wslview https://wsl.tips
$ wslpath -w ~/teste.txt
\\wsl.localhost\Ubuntu\home\matheus\teste.txt
$ wslpath -w /mnt/c/Windows
C:\Windows
$ wslpath -u '\\wsl.localhost\Ubuntu\home\matheus\teste.txt'
/home/matheus/teste.txt
$ wslpath -u 'C:\Windows'
/mnt/c/Windows
$ wslview $(wslpath -w /home/matheus/teste.txt)
$ wslvieww() { wslview $(wslpath -w "$1"); };
$ wslview /home/matheus/teste.txt
$ WIN_PROFILE=$(cmd.exe /C echo %USERPROFILE% 2>/dev/null)
$ WIN_PROFILE_MNT=$(wslpath -u ${WIN_PROFILE/[$'\r\n']})
$ ln -s $WIN_PROFILE_MNT/Downloads ~/Downloads
Windows key + R Type it "services.msc" (quotes not needed) Find OpenSSH Authentication Agent, open its Properties (right-click on it). Make sure your settings look like this:
Startup Type: Automatic
Service Status is Running (click Start to do this =)
$ ssh-keygen -t rsa -b 4096
$ ssh-add ~/.ssh/id_rsa
# On WLS2 Linux distro
$ ssh -T git@github.com
The authenticity of host 'github.com (20.201.28.151)' can't be established.
ED25519 key fingerprint is SHA256:+FiY3wmmM6TuWWhbpZisF/zDAPL0zPMSvHdkr4UvCOqU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
Hi matheuscarino! You've successfully authenticated, but GitHub does not provide shell access.
# On Powershell
PS C:\> ssh -T git@github.com
The authenticity of host 'github.com (20.201.28.151)' can't be established.
ED25519 key fingerprint is SHA256:+FiY3wmmM6TuWWhbpZisF/zDAPL0zPMSvHdkr4UvCOqU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
Hi matheuscarino! You've successfully authenticated, but GitHub does not provide shell access.
$ function set-prompt() { echo -ne '\033]0;' $@ '\a'; }
$ set-prompt "Novo Título"
PS C:\> function Set-Prompt {
param (
# Specifies a path to one or more locations.
[Parameter(Mandatory=$true,
ValueFromPipeline=$true)]
[ValidateNotNull()]
[string]
$PromptText
)
$Host.UI.RawUI.WindowTitle = $PromptText
}
> Set-Prompt "Novo Título 2"
PS C:\> wt.exe -p "PowerShell" --title "This one is PowerShell"`; new-tab -p "Ubuntu-20.04" --title "WSL here!"
*****new-tab *****split-pane
{
"guid": "{9b0583cb-f2ef-4c16-bcb5-9111cdd626f3}",
"hidden": false,
"name": "Custom SSH Connection",
"commandline": "wsl bash -c \"ssh <USER>@<FQDN-or-IPADDRESS>\"",
"colorScheme": "Ubuntu-sl",
"background": "#801720"
},
https://docs.docker.com/desktop/install/windows-install/
$ docker info
$ docker run -d --name docker-nginx -p 8080:80 nginx
-d tells Docker to run this container detached from our terminal (to run it in the background); --name specific the name for the container rather than generating a random one; -p map ports on the host to ports inside the running container; nginx the name of the container image to run (if no version is specified, the latest will be used);
Access your browser http://localhost:8080
$ docker container ls
$ docker container ls -a
$ docker image ls
$ docker stop docker-nginx
$ docker rm docker-nginx
$ echo 'source <(kubectl completion bash)' >>~/.bashrc
PS C:\> wsl --unregister <distro-name>
https://marketplace.visualstudio.com/vscode
• Remote-WSL • Remote-SSH • Remote-Containers
https://code.visualstudio.com/docs/remote/remote-overview
CTRL + SHIFT + P
CTRL + SHIFT + E
F5
CTRL + SHIFT + D
F9
On WSL distro (bash)
$ git config --global core.editor "code --wait"
On Windows hostPowershell
PS C:\>git config --global core.editor "code --wait"
$ git log --graph --oneline --decorate --all
$ git config --global --replace-all alias.logtree 'log --graph --oneline --decorate --all'
$ gitk.exe
$ sudo apt-get install jq
$ echo '[1,2,"testing"]' | jq
PS C:\> Get-Content ./<filename>.json | ConvertFrom-Json
PS C:\> Get-Content ./<filename>.json | ConvertFrom-Json | Select-Object -ExpandProperty title
PS C:\> $data = Get-Content ./wsl-book.json | ConvertFrom-Json
PS C:\> $data.title
PS C:\> $data.parts | Select-Object -ExpandProperty name
PS C:\> $data.parts | select -ExpandProperty name | ConvertTo-Json
PS C:\> $data.parts | ForEach-Object { @{ "Name" = $_.name } } | ConvertTo-Json
PS C:\> $data.parts | ForEach-Object { @{ "Name" = $_.name; "ChapterCount"=$_.chapters.Count } } | ConvertTo-Json
PS C:\> $data.parts | ForEach-Object { @{ "Name" = $_.name; "Chapters"=$_.chapters | Select-Object -ExpandProperty title } } | ConvertTo-Json
PS C:\> $SAMPLE_URL="https://raw.githubusercontent.com/PacktPublishing/Windows-Subsystem-for-Linux-2-WSL-2-Tips-Tricks-and-Techniques/main/chapter-11/02-working-with-json/wsl-book.json"
PS C:\> Invoke-WebRequest $SAMPLE_URL
PS C:\> Invoke-RestMethod $SAMPLE_URL
Universal naming convention (UNC) paths https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
Powershell Execution Policies https://learn.microsoft.com/pt-pt/powershell/module/microsoft.powershell.core/about/about_execution_policies
WSL2-Linux-Kernel https://github.com/microsoft/WSL2-Linux-Kernel
Connecting to GitHub with SSH https://docs.github.com/pt/authentication/connecting-to-github-with-ssh
Testing your SSH connection https://docs.github.com/pt/authentication/connecting-to-github-with-ssh/testing-your-ssh-connection
Install Docker Desktop on Windows https://docs.docker.com/desktop/install/windows-install/
HTTP Status Code https://developer.mozilla.org/en-US/docs/Web/HTTP/Status