2021-10-12-linux Foundation

linux command: it is essentially a program. Many programs are written in c language, such as python, java, c + +, ruby, php, go, etc

[root@localhost ~]# Cat / etc / CentOS release to check the version of linux
CentOS Linux release 7.6.1810 (Core) 
[root@localhost ~]# 
cali@cali:~$ cat  /etc/issue     stay Ubuntu Check the version of the system in
Ubuntu 20.04 LTS \n \l
cali@cali:~$
[root@sc ~]# cd  /
[root@sc /]# mkdir test
[root@sc /]# cd test
[root@sc test]# pwd
/test
[root@sc test]#
[root@sc test]# Yum install vim -y install vim editor
 Last metadata expiration check: 1:08:12 Before, it was implemented at 09:57:32 on Tuesday, October 12, 2021.
software package vim-enhanced-2:8.0.1763-15.el8.x86_64 Installed.
Dependency resolution.
No processing is required.
complete!
[root@sc test]# 

[root@sc test]# vim  hello.c
#include<stdio. h> / / import header function
int main()                   // Declare a main function
{
        printf("hello,world\n");  // Output hello,world
        printf("fengdeyong\n");   // Output fengdeyong
        return 0;             // Return value
}

c language is a high-level language
Machines can only recognize binary
1 0 0 1

Program of human recognition
Compilation: the process of translating a program recognized by a human into a program recognized by a machine according to a certain code

gcc It's a linux Compiler under
[root@sc test]# Yum install gcc -y to install gcc tools

[root@sc test]# gcc  -o hello  hello.c will hello C file compiled into Hello program
[root@sc test]# ls
hello  hello.c
[root@sc test]#
[root@sc test]# . / Hello run hello in the current directory
hello,world
fengdeyong
[root@sc test]#

Interpreter Program: interpret the commands entered by people to the linux system
Interpreter: it is also a program. The Coordinator works with the stored commands and the kernel

Do three very important things:
1. Syntax analysis
2. Find the location where the command is stored
3. Tell the kernel to run the program

[the external chain image transfer fails. The source station may have anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-jfhsfzrn-1645066260962) (C: \ users \ Xixi \ appdata \ roaming \ typora user images \ image-20211207211633123. PNG)]

Kernel: it is the core software in linux. It is also a program and written by people
effect:
1. Manage cpu
2. Manage memory
3. Manage disks
4. Management process
5. Manage other hardware

cpu: the central processing unit is used for computing, which is equivalent to the human brain
Memory: the place where the running program is stored -- "the place where the data is stored –" power failure will lose -- "memory in the brain
Disk: data for programs that don't work -- "where to store data –" for example: infrequently used files, permanent storage – "equivalent to houses, clothes, furniture, etc

Interpreter: shell interpreter -- bash

shell interpreter: it is a kind of program that realizes human-computer interaction. In fact, it is an intermediary

At present, bash is a better shell interpreter in linux

[root@sc test]# Echo $shell: the default shell in the system is bash
/bin/bash
[root@sc test]# 

Internal commands: the commands available after bash is installed are internal commands
External commands: those that need additional installation, not in bash

[the external chain image transfer fails, and the source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-o8mdsqa7-1645066260964) (C: \ users \ Xixi \ appdata \ roaming \ typora \ typora user images \ image-20211207212028446. PNG)]

The terminal running behind xshell is bash – "is an interpreter

Script: it stores the linux commands that need to be executed -- "walking"
The contents are fixed
Something very dead

shell script: it is a program that can execute many Linux commands – "batch complete many Linux commands that need a single input"

Benefits of using shell scripts:

​ 1. Quickly complete many important and repetitive things to save time and energy

[root@sanchuang test]# vim mkdir100.sh script
#!/ "bin/bash --" declares that our script uses the interpreter / bin/bash to interpret and execute

for i in {1..100}
do 
        mkdir tangyuhao$i
done
[root@sanchuang test]# bash mkdir100.sh execute script
[root@sanchuang test]# rm -rf tangyuhao * delete all files starting with tangyuhao, no matter what follows

for loop i Is a variable
in Where to get things
{1..100}   Numbers from 1 to 100   -->Represents a collection
i=1
i=2
 When the content is collected, for The cycle is over
 Dead cycle: cycle all the time without stopping

do Do things
done Done
 according to shell The rules of programming are grammar

*Is a wildcard, representing any character -- a symbol that matches all characters
tangyuhao1
tangyuhao10
tangyuhao100

[root@localhost ~]# echo  123456
123456
[root@localhost ~]# echo  123456|passwd zhang --stdin
 Change user zhang Your password.
passwd: All authentication tokens have been successfully updated.
[root@localhost ~]# 

| Pipe symbol: function: send the output of the previous command to the following command as input
 Middleman: offer Buddha with flowers and push boat with the water


Command 1   |   Command 2
--stdin   standard  input Standard input: linux The specified standard input is from the keyboard
       Function: tell passwd Command, the content sent by the pipeline symbol, you can directly treat it as the content received from the keyboard and set the password for the user!

Write a script:

Create 100 new users

zhangyamin1~zhangyamin100, and set the same password as zhang123456 for 100 users
​ 1. Name the script create_user.sh

[root@sanchuang test]# vim create_user.sh 
#!/bin/bash

for i in {1..100}
do
	 #New user
         useradd   zhangyamin$i
	 #Set password
	 echo 123456|passwd zhangyamin$i --stdin

done

[root@sanchuang test]#bash create_user.sh execute script

#The line comment at the beginning -- "comment", which is explained to people. The machine does not execute it
tab Key: complement file name and command name fo 
Write a script to delete 100 users starting with zhangyamin

Userdel - R zhangyamin1 -- > delete user's command
After the user is deleted, the password will also be deleted
- r function: when deleting users, delete the home directory together

[root@sanchuang test]# vim del_user.sh
#!/bin/bash

for i in {1..100}
do
          userdel -r zhangyamin$i
done
[root@sanchuang test]# bash del_user.sh

Tab key automatic replenishment
Shortcut key Ctrl+C: terminate the current process
Shortcut key Ctrl+L: clear screen, equivalent to clear command
Shortcut key Ctrl+K: delete all characters from the cursor to the end of the line
Shortcut key Ctrl+U: delete the character from the cursor to the beginning of the line
The up and down direction keys can call the previously used commands

home jumps to the beginning of a line
End jumps to the end of a line
backspace -- of deleted content

pwd view the current path
[root@sc test]# man  pwd
 pwd - print name of current/working directory  -->Output the name of the current working directory -->View the current path
cd from current directory to another directory – enter folder

​ Change the current directory to dir. change directory
cd . Enter current directory
cd... Return to previous directory
cd - returns to the last directory
cd ~ enter home directory
cd into home directory
cd ~chenyamin enter chenyamin user's home directory
cd / enter the root directory

[root@sanchuang shaolin]# useradd hejin
[root@sanchuang shaolin]# cd ~hejin
[root@sanchuang hejin]# pwd
/home/hejin
[root@sanchuang hejin]# cd ~chenyamin
[root@sanchuang chenyamin]# pwd
/home/chenyamin
[root@sanchuang chenyamin]# cd -
/home/hejin
[root@sanchuang hejin]# 
Absolute path:

Starting from / and going down layer by layer, you will never make a mistake -- "Shun Teng touching melon"
Command + path
The absolute path has nothing to do with which folder you are currently in
Advantage: never make a mistake
Disadvantages: the path is too long and inconvenient to input

Relative path:

With the current folder as the reference, you can enter or exit
Path that does not start with /
Advantages: fast, not easy to make mistakes
Disadvantages: it's easy to forget where you are now

[the external chain image transfer fails, and the source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-22wqaah3-1645066260965) (C: \ users \ Xixi \ appdata \ roaming \ typora user images \ image-20211207210620897. PNG)]

practice:
1. Create a new wuxia folder under the root directory
2. Build a new wudang huashan mingjiao tianshan shaolin inside
3. Use the absolute path to create a new folder guangmingding in the mingjiao folder
4. Enter guangmingding, and then use the absolute path to create a new henan folder in the shaolin folder
5. Use the absolute path to enter henan
6. Return to the previous path
7. Check which shell is the current shell?
echo $SHELL
8. Write a script to create 20 new folders. The folders start with sanchuang and 30 start with Changsha. They are stored in the / wuxia/huashan directory. The successful effect should be from sanchuan1 to sanchaung20, and from changsha1 to changsha30
Reminder:
Use 2 for loops
9. Create a new script and delete the folder beginning with sanchuang under / wuxia/huashan. The folder beginning with changsha will not be deleted
10. Write a script to create 10 new users. The user name starts with wangxin and the password is set to wang123456
11. Enter wangxin9's home directory
12. Return to the previous directory
A script is used to create 20 new folders. The folders start with Sanchuang and 30 start with Changsha. They are stored in the / wuxia/huashan directory. The successful effect should be sanchuang1 to sanchaung20, changsha1 to changsha30
Reminder:
Use 2 for loops
9. Create a new script and delete the folder beginning with sanchuang under / wuxia/huashan. The folder beginning with changsha will not be deleted
10. Write a script to create 10 new users. The user name starts with wangxin and the password is set to wang123456
11. Enter wangxin9's home directory
12. Return to the previous directory
13. Use the tree command to view the directory structure of / wuxia

Keywords: Linux vim server

Added by zalath on Thu, 17 Feb 2022 04:57:46 +0200