The original article was published in the language finch, but no one read 😭. At present, the article is basically formed, update will be few, moved to nuggets, as my first blog in nuggets. Full tutorial, all knowledge sources are given (but there may be a missing 😂, try), please rest assured to eat

This article does not cover the pros and cons of WSL, but serves as a tutorial on how to get started with Linux using WSL 📃

Permission to reprint, but please do not take out of context and do not post the original link. Not only can not solve the problem of readers, but also affect the possibility of retrieving the original text. Have suffered greatly 😡

I plan to learn Linux, but I haven’t touched it before. I found that I can install Linux subsystem directly on Windows, so I chose to use WSL2 to get started with Linux


12.2.2021 I think I am familiar with various operations of Linux, and the development environment has been basically migrated to WSL2, which is very comfortable and much better than ordinary VIRTUAL machines

process

Step1 download and install WSL2

The official tutorial is the most clear, did not encounter any pits, possible pits official at the bottom of the tutorial is listed below the Microsoft official tutorial there is a Windows terminal installation (optional), it is recommended to install directly, will greatly improve your use experience

After that, all operations are performed on Windows Terminal, using Ubuntu as the distribution of choice

Attachment: quick open a terminal method win + s | | win + q | | three refers to click on the touch pad | | win + r, input wt and then press enter

After opening WT, remember to set the Default profile to Linux and Ubuntu for me

Step2 understand the relevant knowledge of Linux, try the basic Linux command

Reference tutorial www.linuxprobe.com/basic-learn… Learn about Linux. Try some basic Linux commands. However, don’t try all the commands in this tutorial, just play with the basics

Step3 change source

Ali source is currently used, because there were strange problems with Tsinghua source before. But the substitution method is the same

The steps are as follows:

Ubuntu view the current version

 $ cat /etc/issue Mine is Ubuntu 20.04.2 LTS

Other related commands: cat /proc/version uname -a lsb_release -a

Enter the /etc/apt directory

cd /etc/apt
Copy the code

The sources.list file specifies the software source. To be on the safe side, make a backup of your current software source

$ sudo cp sources.list sources.list.bak

Administrator mode Use vim to open sources.list for editing

$ sudo vim sources.list

About VIM, be sure to learn how to use VIM

Delete everything

Enter gg dG

“Gg” indicates to jump to the first line of the file. DG is to delete the cursor line and all lines below it; D indicates delete, G indicates jump to the end of the file.

If entered incorrectly, u will reverse the previous action

Open theUbuntu | Mirror sites use to help | Open Source software, Tsinghua university Mirror station | Tsinghua Open Source MirrorFind your own image for ubuntu

After copying the content, right-click (paste) in WT and save to exit the file:wq

Other source

update

sudo apt-get update sudo apt-get upgrade

You might have a problem, a bunch of errs,W’s, things like thatThe domain name is not resolved properly.reference $ sudo vim /etc/resolv.confTo which add:Nameserver 127.0.1.1 # The DNS server of Aliyun is used here Nameserver 223.5.5.5 Nameserver 223.6.6.6 Save exit this time can be normal update!!

Step4 change the source after completion, try to download a thing

The full name of the tree command is tree. The command is used to list the contents of a directory in a tree diagram. Run the tree command to list all files in a specified directory in a tree diagram, including files in the specified directory. The file directory structure of the specified directory is displayed as follows:However, if you type tree directly, you will find it useless. You need to download software to enter it$ sudo apt install treeTree will download automatically, now you can use Tree you can use$man treeorLinux command to query web sitesView usage

Note: Do not use it in places with many files, otherwise the display will not finish. If it has already started, you can use CTRL + C to forcibly stop the current program execution

What to know: Debian, Ubuntu, Mint, and other Debian-based distributions all use.deb files and DPKG package management systems. There are two ways to install applications from this system. You can use apt to install from a repository or DPKG to install from a.deb file. Let’s see how we can do both. $sudo apt install app_name $sudo apt install app_name $sudo apt remove app_name $sudo apt upgrade What if you only want to update one app? no problem $sudo apt update app_name Finally, assume that the application you want to install does not exist in the Debian repository, but has.deb downloaded. $ sudo dpkg -i app_name.deb

About apt command (Easter egg 🥚)

The new version of APT has been simplified

Apt command Superseded command Functions of commands
apt install apt-get install Installing software Packages
apt remove apt-get remove Removing a Software Package
apt purge apt-get purge Remove software packages and configuration files
apt update apt-get update Refresh the repository index
apt upgrade apt-get upgrade Upgrade all software packages that can be upgraded
apt autoremove apt-get autoremove Automatically deletes unwanted packages
apt full-upgrade apt-get dist-upgrade Dependencies are handled automatically when software packages are upgraded
apt search apt-cache search Search application
apt show apt-cache show Display installation details

🥚 Enter apt-get-h in terminal, “This apt has super cow power” will appear at the end. 🥚 Typing apt-get moo on the terminal will bring up a cow on the screen

                 (__)
                 (oo)
           /------\/
          / |    ||
         *  /\---/\
            ~~   ~~
..."Have you mooed today?".Copy the code

Continue to

Docs.microsoft.com/zh-cn/windo…

WSL Best practices

  • By keeping your development environment completely in WSL and insisting that you don’t install any development software under Windows, you’re actually less likely to run into problems such as path format inconsistency.
  • If you are using an IDE, then the IDE should also try to use the same set of compiler environment on WSL. Remote mode can be considered, remote mode does not work, such as idea, can choose to install Linux version directly. GUI can be done with VCXSRV or something like that.
  • All project files are kept in the WSL so that you don’t really rely too much on cross-system IO speed.
  • All configuration files that need to be managed with Git and other tools are stored in WSL. If some configuration files need to be reused by Windows software, then soft links are used. These configuration file level small files do not care about IO speed, and can be directly soft links are perfect.
  • Use the existing interoperability support only as a back-of-the-line solution, occasionally when you really need it, and try not to rely on it in your frequently used workflow.

All sorts of problems

Official: Troubleshooting

Git error: The TLS connection was non-properly terminated.

Fatal: Unable to access ‘github.com/mattwojo/he… ‘: GnuTLS recv error (-110): The TLS connection was non-properly terminated.

Solution: Sudo

Sudo git clone github.com/mattwojo/he…

How do I restart the WSL if the WSL is shut down due to an accident?

#⭐⭐ Current best solution ⭐⭐
# poweshell input
wsl --shutdown
Copy the code

Port Occupation problem

Problem description: Localhost: part of port number access failure during development, suspected BUG caused by Microsoft pot

12.7.2021

Some port of localhost fails when programming in vscode. The result of self-check should be that the port is occupied. Use task Manager to shut down the process, but it is still unavailable. Solution: Restart WSL WSL –shutdown

12.22.2021

Port failed again and restart WSL invalid guess: the process occupying the port is not actually shut down, and this process is not part of the WSL solution: restart the computer

Pack a few gadgetstodo

10.19.2021 Microsoft Nb 🥳🥳🥳 docs.microsoft.com/en-us/windo

Many current GUIs have unpredictable bugs and are not recommended unless you use them for fun like I did

System Monitor(GUI) 👈

Similar to the Task manager on Windows, it is used to check system resource usage. The Task manager on Windows cannot see the process in the WSL, but only one process is displayedTherefore, the System Monitor is required to check the running status of processes in the WSL

# install (if not present) :
sudo apt-get install gnome-system-monitor
Copy the code

After downloading, fix it in the start menu for easy useI have just opened VScode, through WSL plugin development, I hover the mouse over the System Monitor, the details such as 👇 will tell me that this process is related to VScode-server reference

ImageMagick(GUI)

A tool for processing images, usually directly from the command line

Man Imagemagick to see what it can do convert icon.png icon.ico this will generate an ICO file without deleting the original fileCopy the code

A variety of other commands 👇 can be viewed in detail at man

convert
identify
mogrify
composite
montage
compare
stream
display
animate
import
conjure
Copy the code

Miniconda and pytorch

Please refer to the official tutorial: Enable PyTorch with DirectML on WSL 2 | Microsoft Docs note:

  • If you choose to change the source of wGET, you may get an error when creating the environment. Try to follow the official tutorial
  • runConda create --name pydML python=3.8 -y“Will be promptedconda: command not foundIn this case, modify the. Bashrc file. The procedure is as follows: 👇
    • vim ./.bashrcOpen the file
    • Add at the end of the fileexport PATH=$PATH:/home/mirrorgo/miniconda3
      • Note: The path here should be your own miniconda3 installation location
    • Run after savesource ~/.bashrcRestart environment variables
  • import torchRemember to use it in an interactive Python session, otherwise it will not work
  • If you try to install Anaconda-Navigator later and fail, don’t worry, because I do the same 😭😭😭 can’t find the reason
    • Forget the GUI for now, just the command line

Used in vscode

Error: import ‘package’ cannot be resolved

CTRL + Shift +P, type Select Interpreter to select the InterpreterSelect the environment where the package is installed 👉 such as the PyTorch I used in PyDML

More on Conda

Uninstall Anaconda_Anaconda

jupyter notebook (in vscode)

Miniconda creates a virtual environment that uses VScode’s Jupyter Notebook

  • Install vscode related jupyter extensions
  • Switch to the environment where you want to use JUPyter
  • Create an empty notebook
  • Edit the system image configuration file to add an image
    • vim ~/.condarc
    • Put on the mirror image of Jiaotong University
conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/conda-forge/
Copy the code

Before ∵ may lead to some problems with the other mirror 👈 reference blog

  • Run, prompting you to install the corresponding kernel
    • The IPykernel needs to be installed or updated
  • The installation

www.jianshu.com/p/653c66f0d… Blog.csdn.net/qq_44721831…

Linux Experience Optimization

shortcuts

ctrl+c Forcibly terminates the current command
ctrl+I Clear the screen
ctrl+a The cursor moves to the top of the command line
ctrl+e Cursor moves to end of command line
ctrl+u Deletes from the cursor position to the beginning of the line
ctrl+z Put the command in the background
ctrl+r Search in the history command

The recycle bin

Trash – the Cli: Command line trash bin tool on Linux Trash-put Move files or directories to the trash bin Trash-empty Empty trash-list List trash bin files trash-restore Restore trash bin files trash-rm Delete trash bin files

Search the recycle bin file: $trash – list | grep foo 12:36:00 2007-08-30 / home/Andrea/foo 12:39:41 2007-08-30 / home/Andrea/foo

$ trash-empty

Delete only files that fit a certain pattern: $trash-rm *. O Note: Use double quotes around patterns to avoid shell expansion.

Can I alias rm to trash-put?

You can, but you shouldn’t. I used to think it was a good idea, but NOW I don’t. Although trash-put’s interface looks compatible with RM, they have different syntax, and these differences can cause some problems. For example, when using rm to delete a directory, -r is required, but trash-put is not.

But sometimes I forget to use trash-put. Can’t I alias rm?

You can give rm an alias to remind you not to use it: alias rm=’echo “This is not the command you are looking for.”; false’

If you really want to use rm, cancel the alias by preceded by a slash: \rm file-without-hope

Note that the Bash alias is valid only in the interactive interface, so using this alias does not affect scripts that use RM.

Where are the files that were moved to the recycle bin?

Move the files from the home partition to the recycle bin here: ~/.local/share/Trash/

alias

To make the aliases permanently valid, write the aliases to the environment variable configuration file vi ~/.bashrc ———->>

I use vscode to edit code ~/.bashrc

Alias -p View the permanent alias of all Sometimes the terminal needs to be restarted to take effect

The difference between /etc/bashrc and ~/. Bashrc is that the bashrc is for the global user and the bashrc is for the current user

#all alias alias alert=’notify-send –urgency=low -i ” ([([ ([? = 0 ] && echo terminal || echo error)” “(history|tail -n1|sed -e ‘\”s/^\s*[0-9]\+\s*//;s/[; &|]\s*alert//”’)”‘ alias c=’clear’ alias egrep=’egrep –color=auto’ alias fgrep=’fgrep –color=auto’ alias grep=’grep –color=auto’ alias l=’ls -CF’ alias la=’ls -A’ alias ll=’ls -alF’ alias ls=’ls –color=auto’ alias ping=’ping -c 5′ alias rm=’echo “This is not the command you are looking for.”; false’ alias tl=’trash-list’

Todo: The ideal rm will be prompted when rm is generated

9files will be delete 50.3m in total rm -i Prompt content

Type y after trash-put to move the file or directory to the recycle bin

The alias

10 handy Bash aliases for Linux A normal ping will go on forever. We don’t want that. Instead, let’s limit that to just five pings. alias ping='ping -c 5'

alias c='clear'

The backup

wsl -t Ubuntu
wsl -l -v
wsl --export Ubuntu F:\_wsl_backup\Ubuntu.tar
Copy the code

Huyangjia.com/computer-te…

Unable to correct problems, you have held broken packages.

To download the NVM, run the github.com/nvm-sh/nvm command

nvm

To change the node.js version you want to use for your project, create a new project directory mkdir NodeTest, type CD NodeTest, and then type NVM use Node to switch to the current version, or type NVM use — LTS to switch to the LTS version. You can also use a specific amount of any other version you have installed, such as NVM Use V8.2.1. (To list all available versions of Node.js, use NVM ls-remote.)

NPM WARN Deprecated [email protected]: Use UUID module instead Requires a more advanced version of NPM

nvm install-latest-npm
Copy the code

NPM WARN Deprecated [email protected]: Please upgrade to version 7 or higher.??

www.runoob.com/nodejs/node…

Don’t use CNPM and download the world longer than NPM, why

Problem: the curl: (7) failed to connect to port 443 raw.githubusercontent.com: connection refused solution: hanging ladder

NVM sudo: NPM: command not found

Problem: sometimes apt-get does not download

suggest you install aptitude which can help you resolve conflicts then install your package with aptitude

sudo apt install aptitude
Copy the code

3. Replacing apt-get aptitude can help find some dependent packages

Aptitude, like apt-get, is an extremely powerful package management tool in Debian and its derivatives. Aptitude unlike apt-get is better at handling dependencies. For example, when aptitude deletes a package, it also deletes its dependent package. This way, there are no useless packages left in the system, and the whole system is cleaner.

Aptitude must be used for problems that apt-get cannot solve or problems that aptitude cannot solve.

Aptitude solved better: Install, remove, Scandisk (apt-get unavailable), show (apt-get unavailable), search (apt-get unavailable), hold (apt-get unavailable), Unhold (apt-get does not have this function), apt-get can solve better places: Apt-get (aptitude not available), build-dep (low aptitude not available) update, upgrade (apt-get upgrade=aptitude safe-upgrade, apt-get dist-upgrade=aptitude full-upgrgade)

What is package-lock.json after downloading NPM?

Sudo: NPM: Command Not found Solution: Add soft link blog.csdn.net/m0_46267097… Qastack. Cn/programming…

Linux command advanced

assorted

CD – Returns the directory of the previous layer

Create files and folders quickly

# to create the dir1-name dir2, dir3 dir4, dir5The mkdir dir {1, 2, 3, 4, 5}# to create file1. TXT, file2. TXT, file3. TXT, file4. TXTtouch file{0.. 4}.txt# to create nested folders - no - p will be unable to create) | | substitute - pv - p displays each create operation
mkdir -p dir1/dir2/dir3/dir4/dir5
Copy the code

other

The ls -l www.cnblogs.com/EasonJim/p/… Linuxize.com/post/how-to…

Hard links, soft links blog.csdn.net/youcai35/ar… This bbs.huaweicloud.com/blogs/20701… Metmoon.com/2019/05/29/… Blog.csdn.net/hpuxiaofang… www.cnblogs.com/xiexj/p/721…

Blog.csdn.net/xiaofei0859…

By the way, the “link count” of directory files. When creating a directory, two directory entries are generated by default: “.” and “..” . The inode number of the former is the inode number of the current directory, equivalent to the “hard link” of the current directory. The inode number is the inode number of the parent directory of the current directory, which is equivalent to the “hard link” of the parent directory. Therefore, the total number of “hard links” in any directory is always equal to 2 plus the total number of its subdirectories (including hidden directories), where 2 is the “hard links” of the parent directory and the “hard links” in the current directory. Hard link.

The total number of hard links is calculated as follows: upper input file name + local. + subdirectory..

Disadvantages of soft link: because the link file contains the path information of the original file, so when the original file from a directory to move down to other directories, and then access the link file, the system will not find, and hard link does not have this defect, you want to move how to move; It also requires the system to allocate extra space to create new index nodes and save paths to original files