Linux basics must know and know (1)

Preface

Why learn Linux system?
Many people will wonder, the current visualization operating system is so easy to use, why should we learn the underlying system? Just like when we learn python, we may not understand the source code of the library. We can also work well and use these achievements, but we will never be able to develop further in this direction until the so-called 30-year-old curse. Replaced by younger people

Linux is the same. In our learning process, whether it is big data such as Mysql, hadoop, Pysaprk, or data mining, artificial intelligence operations, we use local, at most, we can get a virtual machine, but the production environment is basically in Operation on the server, so in order to better career development, we still need to learn some Linux knowledge, do not seek refinement, at least the basic operation must be familiar! Even if you learn by yourself, you need to understand the basics of using virtual machines!

First, get to know the Linux operating system

1. Common operating systems:

  • windows, an operating system for ordinary users
  • MacOS, an operating system for ordinary users
  • Linux, positioning is not an operating system for ordinary users

2. Linux is free and an open source operating system for server systems

3. Linux kernel version and release version

  • Kernel version website
  • Kernel version -> secondary development -> add custom functions -> release as a release version

4. Application scenarios of Linux operating system

  • Server: the pursuit of stability and security
  • Embedded development: ATM cash machine, air conditioner remote control, elevator system, etc.
  • Mobile operating system: Android system and iOS system

5. Common distribution versions of Linux operating system

  • CentOS (free)
  • RedHat (Red Hat, service charge)
  • Ubantu (hardly used in the enterprise, optimized graphics and beautiful)

6. Linux operating system download address

Second, the principle of network configuration

Insert picture description here

Three, virtual machine network configuration principle

Insert picture description here

Four, virtual machine network environment configuration

1. Modify the network card configuration file

  • In the Linux operating system, any hardware is a file

  • Edit network card file command: vi /etc/sysconfig/network-scripts/ifcfg-ens33

  • Modify the ifcfg-ens33 file as follows:

    BOOTPROTO=static		#静态IP
    ONBOOT=yes				#开机自动启动网卡服务
    IPADDR=192.168.211.10 	#IP地址
    NETMASK=255.255.255.0	#子网掩码
    GATEWAY=192.168.211.2	#网关IP
    DNS1=192.168.211.2		#域名解析服务器,和网关IP地址一样
    
  • Save and exit the network card file: shift + :, then enter: wq and press enter

  • Restart the network card service to make the configuration take effect, command: systemctl restart network.service

  • View the IP address, command: ifconfig

2. Modify the host name

  • Use the command: hostname to view the current host name
  • Modify the host name: vi /etc/hostname

3. Configure IP mapping

  • Configure the IP mapping file: vi /etc/hosts
    server1 192.168.211.10

Five, remote tool Xshell

Download and install from the official website of xshell.
You can also use other remote tools. Alibaba Cloud can connect directly to the web version.

Six, Linux directory structure explanation

1. Bin directory: commands that can be executed by ordinary users are stored in this directory

2. The sbin directory: commands that can be executed by the root user are stored here

3. Boot directory: stores services related to startup

4. The dev directory: stores the hardware information

5. Etc directory: configuration files related to the system are all in this directory

6, home directory: the home directory of ordinary users

7. The root directory: the home directory of the root user

8. Lib and lib64: code libraries that the system depends on

9. Media directory: media directory, such as inserting a U disk, the content will be displayed in this directory

10. mnt directory: disk mount directory

11. opt directory: all the software installed by ourselves are placed in this directory

12. proc directory: process directory, program process of linux system

13. Tmp directory: Temporary directory. Note: Do not store important files in this directory. System restart may cause file loss

Seven, Linux commonly used command explanation

The format of the command:命令 [-选项] [参数]

1、ifconfig

  • Function: View network card configuration information

2、clear

  • Function: Clear the screen
  • Shortcut key: ctrl + L

3、pwd

  • Function: Print the current directory (absolute path)

4、cd

  • Function: Move to the specified directory
  • Example: cd /etc/sysconfig/network-scripts/

5 、 ls

  • All spelling: list
  • Function: View all files in the directory
  • Example 1: ls #If you do not specify a directory, view all files in the current directory
  • Example 2: ls /etc/sysconfig/network-scripts/ #Check which files are in the specified directory
  • Example 3: The full spelling of ls -l / #-l is long, which means to view the file with detailed information
  • Example 4: ll / #ll is the alias of ls -l, we will usually use ll instead of ls -l
  • Example 5: The full spelling of ls -al / #-a is all, which means to view all files (including hidden files)

6、mkdir

  • All spelling: make directory
  • Function: Create directory
  • Example 1: mkdir dir1 #If no path is specified, dir1 will be created in the current directory
  • Example 2: mkdir /opt/dir2 #Specify to create dir2 in the /opt directory
  • Example 3: mkdir -p parent/son #When creating the son directory, if the parent directory does not exist, add the -p option to indicate recursive creation

7、touch

  • Function: Create file
  • Example 1: touch file1 #If the path is not specified, the file is created in the current directory
  • Example 2: touch /opt/file2 #Specify to create file2 in the /opt directory

8、cp

  • All spelling: copy
  • Function: Copy files or directories
  • Example 1: cp /opt/file2 ./dir1 #copy /opt/file2 to the /tmp/dir1 directory
    • ./ indicates the current directory
    • …/ indicates the upper level directory
  • Example 2: cp -r dir1 parent #Copy the dir1 directory and paste it to the parent directory. Note: Copy directory needs to add -r

9、mv

  • All fight: move
  • Function: Move files or directories, and support renaming
  • Example 1: mv file1 dir #Move file1 file to dir directory
  • Example 2: mv /opt/file2 ./dir/file2.copy #Move the /opt/file2 file to the dir directory and rename it to file2.copy
  • Example 3: mv dir1 dir #Move the dir1 directory to the dir directory

10、rmdir

  • All spelling: remove directory
  • Function: delete empty directories
  • Example: rmdir dir1/dir2 #Delete dir2 directory

11、rm

  • All spelling: remove
  • Function: delete files or directories
  • Note: When deleting a directory, you need to add the -r option, the -f option means forced deletion, no longer ask
  • Example 1: rm file1 #Delete file
  • Example 2: rm -r dir1 #Delete a directory, you need to add the -r option
  • Example 3: rm -rf dir2 #add -f means forced deletion

12、cat more less head tail

  • Function: View files
  • Example 1: cat /etc/passwd #suitable for viewing small files
  • Example 2: more /etc/services #Suitable for viewing large files, support page down (press the space bar)
  • Example 3: less /etc/services #Suitable for viewing large files, support page down (press the space bar), and page up and down (up and down arrow keys)
  • Example 4: head -10 /etc/services #View the first 10 lines of the file
  • Example 5: tail -10 /etc/services #View the last 10 lines of the file

13, poweroff reboot (restart)

  • Function: Shut down

8. Management of users and user groups

1. Types of Linux users

  • root super user
  • general user
  • System (pseudo) user

2. Check which users the Linux system currently has

cat /etc/passwd

The returned information is as follows:

root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:998:996:User for polkitd:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
#返回信息解读,以第一个为例,后面类似
root:x:0:0:root:/root:/bin/bash
- 第一列:用户名root
- 第二列:密码标记位,x代表用户拥有密码
- 第三列:用户ID,也叫做UID
	root用户的UID就是0
	系统用户的UID取值范围是:1~999
	普通用户的UID取值范围是从1000起
- 第四列:用户组ID,也叫作GID
- 第五列:用户的描述信息
- 第六列:用户的家目录
- 第七列:用户所使用的shell

4. Man command to view help information

man rm		#查看命令的帮助信息

5. Basic user operation commands (emphasis)

# 添加用户
useradd zhangsan
# 设置密码
passwd zhangsan
# 删除用户
userdel -r zhangsan #推荐加-r,表示删除用户的同时把用户的家目录一并删除
# 切换用户
su - zhangsan

6. Check which user groups the Linux system has

 cat /etc/group

7. Basic operating commands for user groups

  • Add user group
groupadd teacher
  • Delete user group
groupdel teacher

Conclusion

As the article said at the beginning, in the current era of data explosion, the basic production environment is built on the server, so some basic Linux knowledge still needs to be understood. In addition, there are still some differences between virtual machines and servers. If possible, it is recommended to get a server for fun!

Next: "Linux Basics Must Know and Know (2)"

Guess you like

Origin blog.csdn.net/qq_35866846/article/details/109253964