Home > Article > Operation and Maintenance > 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:
##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.
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 is divided into two types according to the degree of nativeness:
Kernel version:
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!