“This is my seventh day of the first Gwen Challenge 2022.First challenge in 2022”

Linux Quick Start: Basic command collection

Preface:

This article, not for the operation and maintenance level of liunx system learning, but for Java – big data learning, the basic functions needed ~ Linux in a word, is simply an operating system! As a programmer, we have a lot of contact with the operating system every day

PC: Windows, OSX, Linux.. Server: Unix/Linux, Windows Server, OSX… Embedded Devices (smart phones) : Linux, Android, VxWorks, iOS….

Linux’s brief introduction:

Penguin logo: penguins belong to the polar creatures, and the North Pole, this polar does not belong to any country!!Connotation, technology sharing open source learning!!

Linux, full name GNU/Linux, is a free and freely distributed Unix-like operating system, often used in the server. History of Linux: In the 1980s, as the performance of computer hardware continued to improve and the PC market continued to expand, the main operating systems available for computers were Unix, DOS and MacOS. Unix was expensive and didn’t run on PCS; DOS was rudimentary, and its source code was closely guarded by software manufacturers; MacOS is an operating system designed specifically for Apple computers.


That’s when Linus Torvalds, a college student, wants to learn about Intel’s new CPU386. He thinks a better way to learn is to write an operating system kernel. Thus: in 1991, Linus Torvalds developed Linux in imitation of Unix for learning and followed a GNU(Free Software Foundation) technology free sharing principle, so the big guys generously: free, open source sharing out!! 😭 big guy cowhide! It is because of open source, later big bosses can see its internal code structure, and constantly optimize its maintenance ~, so that it gradually: safe and efficient! Support high concurrency… A product of the power of the bosses!


Now: Linux has support from software enthusiasts, organizations, and companies all over the world. In addition to maintaining a strong momentum of development in servers, it has made great progress in personal computers and embedded systems.

Linux classification:

There are two versions of Linux:Kernel versionandRelease version. Kernel version:The version number of the system kernel developed and maintained by the kernel team under Linus.Release:It is customized by organizations and companies based on their own distributions. The most popular distributions in the market are Ubuntu, RedHat, CentOS, Debian, Fedora, SuSE, OpenSUSE, etc.

Learn how to install the Linux OS:

This is a headache, the market drop release version is very much, there are charges.. I learn CentOS7 (in fact, this aspect does not have too big impact, after all, the kernel is the same will not be too different!) ; Also, the operating system most people currently have on the market is: Windows(better graphical interface, lots of non-programmers…). Want to learn Linux but the current system is Windows… This is a big problem that many people face.. Problems with notebook operating systems :(solutions)

System installation (LLinux operating system) Dual system installation VM installation (I use the way, here does not do the VM configuration installation explanation, if you want to emulate me can learn: Linux environment common software installation) //www.centos.org//

Getting close to Linux

Boot login:

Openers launch many programs. They are called services on Windows and daemons on Linux.

After the startup is successful, it will display a text login interface, which is the login interface we often see. In this login interface, the user will be prompted to enter the user name/password. Generally speaking, a user can use the following login methods: Cli login SSH login GRAPHICAL user Interface (GUI) Login The user with the highest permission is root. Password: 123123 My password…

Shutdown:

In the Linux domain mostly used in the server, rarely encountered shutdown operation. After all, the server is running a service forever, except in special circumstances, only have to shut down. Shutdown command: shutdown

 sync                Synchronize data from memory to hard disk.In Linux, to speed up data reading, by default, some data that has been loaded into the memory is not written back to the disk, but cached in the memory first. In case your system shuts down abnormally due to some unusual situation, because the data has not been written to the hard disk, wow! So it will cause the data upgrade is not normal! Input sync directly in the text interface, and the data in memory that has not been upgraded will be written to the hard disk! This command is very important before shutting down or restarting the system. It's best to run it several times (2-4 times)! shutdown# shutdown commandShutdown - 10 hThis command tells you that the computer will be shut down in 10 minutesShutdown - h now# Switch off immediatelyShutdown - h a trapThe system will shut down at 20:25 todayShutdown - r nowThe system restarts immediatelyShutdown - r + 10The system will restart in 10 minutes
 reboot              Shutdown -- r now
 halt                # Shutdown the system, equivalent to shutdown -h now and poweroff
Copy the code

To summarize, whether you reboot or shut down the system, first run sync to write the data in memory to disk.

System directory structure

After logging in to the system, enter the following command in the command window: ls/ Tree directory structure :(everything in Linux is mounted under this/root node) Here is an explanation of these directories:

Directory name instructions
/ Linux system root directory
/bin Bin, short for Binary, is the directory that houses the most frequently used commands.
/dev Dev, short for Device, houses Linux peripherals, which are accessed in the same way as files.
/etc This directory is used to store all configuration files and subdirectories required by system management./etc/profile: Linux operating system
/home User’s home directory. In Linux, each user has his or her own directory, which is usually named after the user’s account.
/lib This directory stores the system’s most basic dynamic connection shared library, its function is similar to Windows DLL files.
/usr A very important directory, a user’s many applications and files in this directory, similar to the Program Files directory under Windows. I also like to install all the tools here/usr/local)
/opt This is the directory for additional software installation on the host. For example, if you install an ORACLE database, you can put it in this directory. The default is empty.
/root This directory is the home directory for system administrators, also known as superprivileges.
/var This directory houses things that are constantly expanding, and we are used to putting directories that are constantly being modified in this directory. Includes various log files
/run Is a temporary file system that stores information since the system was started. Files in this directory should be deleted or cleared when the system restarts
More…

Linux Directory Management

We know that the Linux directory structure is a tree structure. The top level directory is root/absolute path: write from root /, for example, /usr/share/doc. Relative path: a path that does not start with /. For example, /usr/share/doc can be written as CD.. /man, that’s the relative path. . Return the previous level /main to the main path ~

Common commands for working with directories

 pwd [-p]                            # check the current directory, add -p: PWD -p to show the actual path, instead of using the link path.
 cdRelative/absolute path# open directoryThe ls - a# View the files in the directory, along with the hidden files. (often used)Ls -l or ll# View the file under the directory, including the file properties and permissions and other data; (Does not include hidden files, often used)
 ls -al                              # View files under directory, including file properties and permissions and other data, together with hidden files;Mkdir [-mp] Specifies the directory nameCreate file directory;
     #-m: Configuration file permissions oh! Directly configure, do not need to look at the default permissionMkdir -m 777 file name;#777: highest permission;
     #-p: help you recursively create the directories you need directly (including the upper level directories)! (Create multi-level directory structure)
     mkdir -p test1/test2/test3      #Linux cannot create this directory directly. -p can create a multi-level directory.Rm -rf Directory or fileDelete a file or directory;
     #rm [-fir] file or directory
     #-f: ignore files that do not exist, no warning message will be displayed;
     #-i: Interactive mode, which asks the user whether to take action before deleting
     #-r: Recursive delete! Most commonly used in directory deletion! This is a very dangerous option!! (Including subdirectories)Mv [-fiu] [File/Directory][File/Directory]# move file or change file name;
     File 2: mv [file 1][file 2]
     # move files from directory 1 to directory 2: mv [directory 1]
     # move file to directory: mv [file] [directory]
     If the target file already exists, it will be overwritten without being asked.
     #-i: overwrite if the destination file already exists.
     #-u: update only if the source file already exists
     
 cp                                  Copy files or directories
     #cp [-adfilprsu]
     #-r: recursive continuous replication, for directory replication behavior; (common)
     #-i: if the destination file already exists, the action will be asked before overwriting.
     #-p: copy the file with its properties instead of using the default properties (often used for backups);
     If the target file already exists and cannot be opened, remove it and try again.
     # a: equivalent to -pDR, for PDR please refer to the following instructions; (common)
     # copy all files and folders from directory 1 to directory 2: cp -r
     Cp -ri [directory 1][directory 2]
Copy the code

Linux File Properties

Linux system is a typical multi-user system, where different users are in different positions and have different permissions. To protect system security, The Linux system has different permissions for different users to access the same file (including directory files).

We can use it in LinuxllorThe ls - lCommand to display the properties of a file and the users and groups to which the file belongs: In Linux, the first character indicates whether the file is a directory, file, link file, etc. :[d] indicates a directory. [-] indicates a file. If [L], it is a link file. If [b] represents a storage interface device (random access device) in the device file; [c] indicates a serial port device in a device file, such as a keyboard or mouse (a one-time reader device).

The following characters are a group of three characters that are the combination of the three parameters of “RWX”.Among them:rStands for readwStands for writexIndicates execute. Note that the positions of the three permissions do not change, and if there is no permission, a minus sign appears-And nothing more.Groups of three each group represents a type of permission: These nine characters are in groups of three! Among them, we can use numbers to represent each authority. The comparison table of scores of each authority is as follows:

 r:4     w:2         x:1
Copy the code

The three permissions (R/W /x) of each identity (owner/ Group /others) need to be added. For example, when the permission is:

Owner = RWX = 4+2+1 = 7 group = RWX = 4+2+1 = 7 Others = — = 0+0+0 = 0 CHmod 770 Owner/group user has: read/write operations (permissions)

CHGRP: modifies file attributes

Chmod [-r] u+ permission,g+ permission,o+ permission File/directory chmod [-r] Permission value File or directory# -r: Recursively change the file ownership group. If the -r parameter is added to change the ownership group of a directory file, the ownership group of all files in the directory will be changed.
Copy the code

View the contents of Linux files

Cat [-abentv] file name -a: lists special characters instead of whitespace -b: lists the line number, only for non-blank lines do not mark the line number! -e: displays the ending line break byte $. -n: prints the travel number, as well as the blank line number, which is different from the option of -b. -t: displays the [TAB] key as ^I. Tac is displayed from the last line. You can see that TAC is written cat backwards! Syntax: tac [-abentv] filename nl display when the output line number! Syntax: nl [-bnw] File name -b: specifies the line number. There are two ways to specify the line number. -b a: lists the line number regardless of whether the line is empty (similar to cat-n). -b t: If there are empty lines, do not list the line number of the empty line (default value). -n: line numbers are displayed in the following three ways: -n ln: line numbers are displayed on the left of the screen. -n rn: The row number is displayed to the right of its column without adding 0. -n rz: The line number is displayed on the right of the column and 0 is added. -w: indicates the number of digits occupied by the row number column. More displays the contents of a file page by page. There are several keys you can press during the running of the more program: Enter: indicates to scroll down a row. / string: indicates that in the displayed content, search down for the keyword "string"; :f: Immediately displays the file name and the number of lines currently displayed; Q: Indicates that the more file is not displayed immediately. B or [CTRL]-b: page back, but this action is only useful for files, not pipes. Less is similar to more, but better than more, it can move on! Syntax: less File name blank key: scroll down a page; [pagedown] : turn down a page; [pageUp] : Turn up a page; / string: The ability to search down "string"; ? String: The ability to search up "string"; N: Repeat the previous search (and/or? About!) N: Repeat the previous search in reverse (and/or? About!) Q: Leave less; Syntax: head [-n number] file options and parameters: -n followed by a number, representing the meaning of several lines! By default, the first 10 lines are displayed! Tail [-n number] tail [-n number] by default, the last 10 lines are displayed. The tail file shows the last ten lines of the file!Copy the code

Linux file editing command Vi

Vi: Linux a powerful full-screen text editor: vi command

Open the file: vi [file name] If the file name does not exist, create a file write ~ Enter editing mode: I, a Exit editing mode: press Esc to enter command mode: : Save and exit: wq or x exit but do not save: q! Save the wCopy the code

Linux user/user group

A user is a group of users with the same characteristics. Each user in Linux belongs to the following user group: root user: a user with the highest permission in Linux

**id**: Displays the UID and GID of the current user**whoami**: Displays the current login user**groups**: Displays the group to which the current user belongs**useradd [user name]**: Add a user**useradd -u [UID] user name **: add user and specify UID to switch to specified user:** 'su [username]' **


**passwd [username]**: Changes the user password**userdel [username]**: Delete a user.* * usermod "l [A new user name] (#) * *: Changes the user login name[usermod - g * *The new group name] (#) * *: Changes the group to which a user belongs**groupadd [group name]**: Add a group[groupadd - g * *Group GID] (#) * *Add a group and specify a GID that corresponds to the concept of user and user group in Linux. I don't know much about it, but I specify: root user is the most powerful user.Copy the code

Extension: Linux link concept

There are two types of Linux links: Hard links and Symbolic links.

Clear Linux Clear the screen

Linux processes and programs

What is a process? A process is a dynamic description of how a program runs, and the process life cycle.

Here is a brief introduction, after all, I am not a professional drop ~Linux Viewing process:Ps – ef | grep (process id) Stop the process:Kill -9 [PID]Specifies the process PID to kill the process!Example:

Ps -ef Query all processes. In the ifconfig output for 192.168 string ifconfig | grep search and Java related process 192.168 ps – ef | grep Java search and related information of ps – 3306 ef | grep, 3306


Kill 2868 Kill process numbered 2868 kill -9 2868 Forcibly kills a process