


Introduction to basic knowledge of Linux (essential for backend)
This article will introduce to you the basic Linux knowledge necessary for back-end programmers. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
Before learning Linux, let’s first briefly understand the operating system.
Start with understanding the operating system
1.1 Introduction to the operating system
I introduce what operating system is through the following four points:
- The operating system (Operation System, referred to as OS) is a program that manages computer hardware and software resources. It is the core and cornerstone of the computer system. ;
- The operating system is essentially a software program running on the computer;
- Provides an operating interface for users to interact with the system;
- The operating system is divided into kernel and shell (we can understand the shell as the application program surrounding the kernel, and the kernel is the program that can operate the hardware).
##1.2 Simple classification of operating systems
Windows: Currently the most popular personal desktop operating system, everyone knows it without much introduction.
Unix: The earliest multi-user, multi-tasking operating system. According to the classification of operating systems, it is a time-sharing operating system. Unix is mostly used on servers, workstations, and now also on personal computers. It plays a very important role in creating the Internet, computer network or client/server model.
Linux: Linux is a Unix-like operating system that is free to use and spread freely. There are many different Linux versions of Linux, but they all Using Linux kernel. Linux can be installed on a variety of computer hardware devices, such as cell phones, tablets, routers, video game consoles, desktop computers, mainframes, and supercomputers. Strictly speaking, the word Linux itself only refers to the Linux kernel, but in fact people are accustomed to using Linux to describe the entire operating system based on the Linux kernel and using various tools and databases of the GNU Project.
2 A first look at Linux
##2.1 Introduction to LinuxWe have already introduced Linux above, and we only emphasize three points here.
- Unix-like system:
- Linux is a free, open source Unix-like operating system Linux kernel:
- Strictly speaking Say, the word Linux itself only means the Linux kernel The father of Linux:
- A legendary figure in the field of programming. He is the earliest author of the Linux kernel, and later initiated this open source project. He serves as the chief architect and project coordinator of the Linux kernel. He is one of the most famous computer programmers and hackers in the world today. He also initiated the Git open source project and is the main developer.
2.2 Introduction to the birth of Linux##In 1991, amateur computers in Finland Enthusiast Linus Torvalds wrote a system similar to Minix (a Unix-like operating system based on a microkernel architecture) and was named Linux by the ftp administrator. It was added to the GNU Project of the Free Software Foundation;
- Linux started with a As a symbol, the cute penguin symbolizes courage and love for life.
Linux is divided into two types according to the degree of nativeness:
Kernel version:
- Linux is not an operating system. Strictly speaking, Linux is just the kernel in an operating system. What is the kernel? The kernel establishes a communication platform between computer software and hardware. The kernel provides system services, such as file management, virtual memory, device I/O, etc.;
- Release version: Some organizations or companies A re-released version based on secondary development of the kernel version. There are many types of Linux distributions (ubuntu and CentOS are widely used, and beginners are advised to choose CentOS), as shown in the figure below:
3.1 Introduction to Linux File System
In the Linux operating system, all resources managed by the operating system, such as network interface cards, disk drives, printers, input and output devices, ordinary files or directories are regarded as a file. That is to say, there is an important concept in the LINUX system: Everything is a file. In fact, this is a manifestation of the UNIX philosophy, and Linux was rewritten from UNIX, so this concept has been passed down. In UNIX systems, all resources are regarded as files, including hardware devices. The UNIX system treats each piece of hardware as a file, usually called a device file, so that users can access the hardware by reading and writing files. 3.2 File Types and Directory Structure Linux supports 5 file types: The directory structure of Linux is as follows: The Linux file system has a distinct structure, like an inverted tree, with the top level being its root directory: Common directory description: 4 Basic Linux Commands The following are just some of the more commonly used commands. I recommend a Linux command quick check website, which is very good. If you forget some commands or don’t understand some commands, you can get solutions here. Linux command list: http://man.linuxde.net/ 4.1 Directory switching command 4.2 Directory operation commands (add, delete, modify, check) 1. mkdir directory name: 2. ls or ll 3. Find directory parameters : Note: The syntax of mv can not only rename the directory but also rename various files, compressed packages, etc. The mv command is used to rename files or directories, or move files from one directory to another. Another usage of the mv command will be introduced later. Note: mv syntax Not only can you cut directories, but you can also cut files and compressed packages. In addition, the results of mv and cp are different. mv seems to have "moved" the files, and the number of files has not increased. When cp copies files, the number of files increases. Note: The cp command can not only copy directories but also files, compressed packages, etc. When copying files and compressed packages, there is no need to write -r recursively Note: rm can not only delete directories, but also delete other files or compressed packages. In order to enhance everyone’s memory, no matter you delete any directory or file, use it directly 4.3 File operation commands (add, delete, modify and check) ##cat/more/less/tail file name In actual development, the main function of using the vim editor is to modify the configuration file. The following are the general steps: file 4.4 Operation commands for compressing files Packaged files in Linux are generally .tar At the end, compression commands generally end with .gz. Generally, packaging and compression are performed together, and the suffix name of the packaged and compressed file is generally .tar.gz. c: Package file v: Display the running process f: Specify the file name For example: There are three files added to the test directory: aaa.txt bbb.txt ccc.txt, if we want to package the test directory and specify the compressed package name as test.tar.gz, we can use the command: tar -zcvf test.tar.gz aaa. txt bbb.txt ccc.txt or: Command: tar [-xvf] compressed file Among them: x: represents decompression Example: 1 To decompress test.tar.gz under /test to the current directory, you can use the command: 2 Extract test.tar.gz under /test to the root directory /usr: 4.5 Linux permission commands Every file in the operating system has specific permissions, users and groups to which it belongs. Permissions are a mechanism used by the operating system to restrict resource access. Permissions in Linux are generally divided into three groups: readable, writable and excutable. Corresponding to the owner, group and other users of the file respectively, this mechanism is used to limit which users and which groups can perform what operations on specific files. Through the Example: In any directory The information in the first column is explained as follows: Type of file: Permissions in Linux are divided into the following types: The difference between file and directory permissions: For files and directories, read and write execution have different meanings. For files: For directory: Every user in Linux must belong to a group and cannot be independent from outside the group. In Linux, each file has the concepts of owner, group, and other groups. is generally the creator of the file. Whoever creates the file automatically becomes the owner of the file. Use ls-ahl You can use the command to see the owner of the file. You can also use chown username filename to modify the owner of the file. When a user creates a file, the group in which the file is located is the group in which the user is located. Use the ls-ahl command to see All groups of the file can also use chgrp group name file name to modify the group where the file is located. Except for the owner of the file and the user in the group, all other users of the system are other groups of the file Command to modify the permissions of files/directories: Example: Modify the permissions of aaa.txt under /test to the owner All permissions, the owner's group has read and write permissions, The above example can also be represented by numbers: chmod 764 aaa.txt Add one Commonly used things: If we install a zookeeper, what should we do if we ask it to start automatically every time we turn on the computer? 4.6 Linux User Management Linux system is a multi-user, multi-tasking time-sharing operating system, any one needs to use system resources All users must first apply for an account from the system administrator, and then enter the system as this account. On the one hand, user accounts can help system administrators track users who use the system and control their access to system resources; on the other hand, they can also help users organize files and provide security protection for users. . Linux user management related commands: The useradd command is used to create new system users in Linux. useradd can be used to create user accounts. After the account is created, use passwd to set the password for the account. You can use userdel to delete the account. The account created using the useradd command is actually saved in the /etc/passwd text file. The passwd command is used to set user authentication information, including user password, password expiration time, etc. System administrators can use it to manage system user passwords. Only administrators can specify user names, and general users can only change their own passwords. 4.7 Linux system user group management Each user has a user group, and the system can manage all users in a user group Carry out centralized management. Different Linux systems have different regulations on user groups. For example, a user under Linux belongs to a user group with the same name. This user group is created at the same time when the user is created. The management of user groups involves the addition, deletion and modification of user groups. The addition, deletion and modification of groups are actually updates to the /etc/group file. Commands related to the management of Linux system user groups: 4.8 Other commonly used commands Note: If you use ps directly (( Process Status)) command will display the status of all processes. It is usually combined with the grep command to view the status of a certain process. First use ps to find the process, and then use kill kill Network communication command: For more Linux knowledge, please visit the Linux Tutorial column!
cd usr
: Switch to the usr directory under this directory:
Switch to the upper level directory Switch to the system root directory
Switch to the user’s home directory
Switch to the previous directory
Add directory
(ll is the abbreviation of ls -l, the ll command can be used to see the detailed information of all directories and files in the directory): View directory information
Find directory (check)
Example:
find .
/home
directory and end with .txt File name: find /home -name "*.txt"
find /home -iname "*.txt"
find . \( -name "*.txt" -o -name "*.pdf" \)
or find . -name "*.txt" -o -name "*.pdf"
4, mv directory name new directory name
: Modify the name of the directory (change) 5. mv directory name new location of directory
: Move directory location --- cut (change) 6. cp -r directory name directory copy target location
: Copy directory (change), -r represents recursive copy 7, rm [-rf] directory
:Delete directory (delete)rm -rf
Directory/file/compressed package
Note: The command tail -f file can dynamically monitor a certain file, such as the tomcat log file. The log will change as the program runs. You can use tail -f catalina-2016-11-11.log Monitor file changes
touch file name
: File creation (increment) File viewing (check)
:
Only the last screen content can be displayed:
can display the percentage, enter can go down a line, space can go down a page, q can exit the view:
You can use PgUp and PgDn on the keyboard to page up and down, q to end viewing :
View the last 10 lines of the file, Ctrl C to end
:
Modify the content of the file (change)vim editor is a powerful component in Linux and an enhanced version of the vi editor. There are many commands and shortcuts for the vim editor, but they are not explained here one by one. You do not need to study them thoroughly. Use vim to edit and modify You just need to be able to use the file method basically.
Delete file (delete)
Delete in the same directory: Memorize rm -rf
tar -zcvf Pack the compressed file name to pack the compressed file Among them:
z: Call the gzip compression command for compression tar -zcvf test.tar.gz /test/
tar -xvf test.tar.gz
tar -xvf xxx.tar.gz -C /usr
(-C represents the specified decompression location )ls -l
command we can view the permissions of files or directories in a certain directoryls -l
The file types will be explained in detail below. , what are the permissions and file owners, groups and other groups in Linux?
Permission name
Executable operations
r
You can use cat to view the contents of the file
w
You can modify the contents of the file
x
Can run it as a binary file
Permissions Name
Executable operations
r
You can view the list under the directory
w
You can create and delete files in the directory
x
You can use cd to enter the directory
Let’s take a look at how to modify the permissions of files/directories.
chmod
Other users only have read permissionschmod u=rwx,g=rw,o=r aaa.txt
chmod x zookeeper
chkconfig --add zookeeper
chkconfig --list
useradd option username
: add user account userdel option username
: delete user accountusermod option username
: modify accountpasswd username
: change or create user Passwordpasswd -S username
: Display user account password informationpasswd -d username
: Clear user password
groupadd option user group
: Add a new user groupgroupdel User group
: To delete an existing user groupgroupmod option User group
: Modify the attributes of the user group
pwd
: Display the current locationgrep The string to be searched The file to be searched--color
: Search command, --color represents highlighting ps -ef
/ps aux
: These two Both commands view the current running processes of the system. The difference between the two is that the display format is different. If you want to view a specific process, you can use this format: ps aux|grep redis
(View the process including the redis string) kill -9 pid of the process
: Kill the process (-9 means forced termination.)
shutdown
: shutdown -h now
: Specify an immediate shutdown now; shutdown 5 "System will shutdown after 5 minutes"
: Specify a shutdown after 5 minutes and send a warning message to the logged in user. reboot
: reboot
: Reboot. reboot -w
: Make a simulation of restarting (only recording will not actually restart).
The above is the detailed content of Introduction to basic knowledge of Linux (essential for backend). For more information, please follow other related articles on the PHP Chinese website!

The five core components of the Linux operating system are: 1. Kernel, 2. System libraries, 3. System tools, 4. System services, 5. File system. These components work together to ensure the stable and efficient operation of the system, and together form a powerful and flexible operating system.

The five core elements of Linux are: 1. Kernel, 2. Command line interface, 3. File system, 4. Package management, 5. Community and open source. Together, these elements define the nature and functionality of Linux.

Linux user management and security can be achieved through the following steps: 1. Create users and groups, using commands such as sudouseradd-m-gdevelopers-s/bin/bashjohn. 2. Bulkly create users and set password policies, using the for loop and chpasswd commands. 3. Check and fix common errors, home directory and shell settings. 4. Implement best practices such as strong cryptographic policies, regular audits and the principle of minimum authority. 5. Optimize performance, use sudo and adjust PAM module configuration. Through these methods, users can be effectively managed and system security can be improved.

The core operations of Linux file system and process management include file system management and process control. 1) File system operations include creating, deleting, copying and moving files or directories, using commands such as mkdir, rmdir, cp and mv. 2) Process management involves starting, monitoring and killing processes, using commands such as ./my_script.sh&, top and kill.

Shell scripts are powerful tools for automated execution of commands in Linux systems. 1) The shell script executes commands line by line through the interpreter to process variable substitution and conditional judgment. 2) The basic usage includes backup operations, such as using the tar command to back up the directory. 3) Advanced usage involves the use of functions and case statements to manage services. 4) Debugging skills include using set-x to enable debugging mode and set-e to exit when the command fails. 5) Performance optimization is recommended to avoid subshells, use arrays and optimization loops.

Linux is a Unix-based multi-user, multi-tasking operating system that emphasizes simplicity, modularity and openness. Its core functions include: file system: organized in a tree structure, supports multiple file systems such as ext4, XFS, Btrfs, and use df-T to view file system types. Process management: View the process through the ps command, manage the process using PID, involving priority settings and signal processing. Network configuration: Flexible setting of IP addresses and managing network services, and use sudoipaddradd to configure IP. These features are applied in real-life operations through basic commands and advanced script automation, improving efficiency and reducing errors.

The methods to enter Linux maintenance mode include: 1. Edit the GRUB configuration file, add "single" or "1" parameters and update the GRUB configuration; 2. Edit the startup parameters in the GRUB menu, add "single" or "1". Exit maintenance mode only requires restarting the system. With these steps, you can quickly enter maintenance mode when needed and exit safely, ensuring system stability and security.

The core components of Linux include kernel, shell, file system, process management and memory management. 1) Kernel management system resources, 2) shell provides user interaction interface, 3) file system supports multiple formats, 4) Process management is implemented through system calls such as fork, and 5) memory management uses virtual memory technology.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools
