This is the 9th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

CMD basic commands

Linux Basic Commands

Install the software

Introduction to WSL

Try Windows Sub System for Linux.

The installation

Enable the WSL function

  1. According to theWinKey – > inputThe control panelPress Enter -> left to findUninstall programAnd click the
  2. Click on the left menuEnable or disable Windows functions
  3. Scroll down and checkWindows subsystem for Linux
  4. Click on the bottom right cornerdetermine
  5. After the startup is complete, restart the computer to complete the installation, and clickRestart immediately

Install Ubuntu

A distribution of Linux

  1. Press Win key -> click right side Microsoft Store ✌ search app Store

  2. Search Ubuntu -> go to the details page

  3. Click on the get

  4. Sign up for a Microsoft account if you don’t have one

  5. Once you have logged in successfully, click install

  6. After the installation is complete, click Start

  7. Waiting for installation to complete

# what is displayed while installing
Installing, this may take a few minutes...
# what will be displayed after the installation is complete
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: fzf
Enter password: 1234
Copy the code

Start the

  1. Hit Start again

  2. When you enter the window, press Enter

# you can see the following welcome screenWelcome to Ubuntu 20.04.2LTS (GNU/Linux 4.4.0-19041-Microsoft x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage ... fzf@DESKTOP-4UTTTAO:~#
Copy the code

!!!!!!!!! Note “PS” install the best to restart the computer oh ~

A more usable terminal

  1. Go back to the MicroSoft Store and install Windows Terminal

  2. Press Win to find Windows Terminal

  3. Right click -> More -> Select Fixed to taskbar

  4. Launch it in the taskbar

The Linux foundation

The base command is similar to CMD

The file system

Everything in Linux is file-based

The top-level directory is called /

The user directory is ~ and the path is /home/xxx

Take a look at the current directory
pwd
# Where is this?
/mnt/c/Users/nmdfzf404

Switch to the root directory
cd / ✌ cd ../..

# see what's in the root directory
ls
bin   dev  home  lib    lib64   media  opt   root  sbin  srv  tmp  var
boot  etc  init  lib32  libx32  mnt    proc  run   snap  sys  usr

# home
cd ~ ✌ cd/ home/FZF ✌cd /home/fzf
Copy the code

Basic commands

# Check the current directory
pwd

# change directory
cd <path>

# Check the contents of the directory
ls <path> # list all directories
  -lah # details all | | file size

Create a new file
touch <file_name>

Create a directory
mkdir <folder_name>

# mobile | renamed
mv <source> <target>

# copy
cp <source> <target>

# delete file
rm <file_name>

# View file contents
cat <file_name>

# remove
rm *				Delete files only
# Caution!!
rm -rf .		Delete everything in the current folder

# Search for file contents
grep hello.txt -e hi

Add sudo when operating on a path outside the home directory
sudo touch demo.txt

Use admin privilegesSudo < command >Copy the code

The operator

# redirect
> # to cover
>> # additional

Example #
echo "Some Text" > hello.txt
cat hello.txt
echo "Some Text2" > hello.txt
cat hello.txt
echo "Some Text3" >> hello.txt
cat hello.txt

# pipeline
|
Example #
ls -l / | grep bin Search for bin in the root directory

# transit
tee Save the output to a file and continue down
Example #
ll /usr/bin | tee software.log | grep python
Copy the code

Install the software

Change the password of the administrator account
sudo passwd

# Switch to administrator
su root

# Change the download source of software to domestic
bash <(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh)

Get the latest software list
apt update

Install a fun app
apt install sl
alias ls=sl # a parody

# Another fun app
apt install cowsay

# Graphical file browser
apt install ranger

# Color process management
apt install htop

Install the C environment
apt install gcc

Write a C program
vim demo.c
gcc demo.c -o demo
./demo

# end
Ctrl+C
Copy the code

Connection vscode

  1. Install plug-in: remote-WSL

  2. Sidebar: Remote Explorer

  3. Connect to the WSL

  4. Create a working directory and enter

Create a directory
mkdir ~/work-space
Open with VScode
code ~/work-space
Copy the code
  1. Write c program
#include <stdio.h>

int main(a) {
printf("Hello World");
return 0;
}
Copy the code
  1. run
# compiler
gcc demo.c -o demo
# run
./demo
Copy the code

After class,

homework

  1. Try all the commands described
  2. To install some fun Linux software, refer to the recommended reading below

Recommended reading

40 super fun Linux command line eggs and games

After reading this article Linux basic operation will be