directory

    • Introduction to the
    • The Linux version
    • Linux Basics
      • The system catalog
      • Common System Commands
        • Modify \ view directory
        • Create \ delete directory
        • Vi, vim command
        • Refer to the file
        • Query file or text content
        • View the directory where the command resides
        • Move the file (Paste and copy)
        • Compression and decompression
        • View the port and process number
    • User, user group, and permission
      • Users and user groups
      • permissions
    • HelloWorld for Shell scripting
    • conclusion

# Linux

Introduction to the

Linux is a free and open source operating system. There are many versions of Linux. Linux runs on a variety of devices, such as phones, tablets, routers, TVS, computers, supercomputers, etc. Linux is currently the preferred server system.

The Linux version

Ubuntu, centos, RedHat, SuSe, and Debian are the most popular Linux operating systems in China.

Linux Basics

What operations do you usually perform in the operating system? View directories, select directories, copy, paste, move, Create a file, delete a file, edit a file.... Now we will learn how to do this in LinuxCopy the code

The system catalog

The root directory for Linux is "/". In this root directory and subdirectories, as well as the role of each subdirectory.Copy the code
/ The root directory
/root Directory of the system administrator
/bin A directory for storing all Linux commands and tools, similar to the bin directory of tomcat
/sbin Command of the system administrator
/etc Files for system configuration, such as Java environment variable configuration, are located in this directory
/dev Files related to external devices, such as printers, mouse drivers, etc., are stored in this folder
/home The directory in which ordinary users reside is a bit like the User directory in Windows
/tmp This folder is used to store temporary files of the system or software. Linux periodically cleans this folder
/usr For example, you can save the installation software in usr/bin
/opt Optional application installation directory into which you can install software that is used only once
/var Stores configuration files that are frequently changed during system execution
/boot Some files used to start the system
/lib Some function libraries that are required during system execution depend on files
/srv Directory for storing data after the system is started
/mnt、/media Default mount point for CD or mobile storage

Common System Commands

Modify \ view directory

Change the directory CD directory name View the directory ls directory name (view the current directory if you do not write the directory) -l Detailed list -a All filesCopy the code

Create \ delete directory

Creating a directory mkdir directory name Deleting a directory rm Directory name -r Traversing all subdirectories -f Forcibly deleting a directoryCopy the code

Vi, vim command

Create/open file VI file name three modes: Command mode Delete, copy, paste, cannot edit input mode Edit content Command line mode Exit, save file Operation mode: Enter command mode by default, press I to enter input mode, press Esc to return to command mode, press: Enter the command line mode Command mode x Delete a character DD delete a line YY copy a line P paste U Undo command line mode wq Save exit q Exit (if there is a change, this way will fail to exit) q! Forced out ofCopy the code

Refer to the file

Cat Displays the entire file content (not supported by paging). More displays the file content in more pages. Less displays the file content in less pages, which is more powerful than more. (support before and after paging query) support text search, / search content down query; ? Exit the less mode and click Q to compare the vi commands. Cat, more, and less are only used for text reading commands, and vi is used for text editing commands. Query whether the current file contains Java words, if all lines containing Java words are displayed. The cat filename | grep query languagesCopy the code

Query file or text content

Find find find -name file name lookup directory | grep nameCopy the code

View the directory where the command resides

Which command nameCopy the code

Move the file (Paste and copy)

Mv Source file Destination file cp Source file (path + file name) Destination file (path + file name)Copy the code

Compression and decompression

Decompress command: tar -zxvf Decompress command: tar -zcvf-z: indicates the compression and decompression format. Compressed file (gzip) -c: : indicates the compression. -x: indicates the decompression. TXT tar -cvf Name of the compressed file File to be compressed tar -xvf Name of the decompressed package to be decompressedCopy the code

View the port and process number

Through the port to check the process: netstat - apn | grep through port 8080 to check the process: lsof - I: 3306 through the process name lookup process: ps - ef | grep redis kill process for process ID: Kill -9 PID (process ID) (-9 indicates forcible kill)Copy the code

User, user group, and permission

Users and user groups

Add user

Useradd -g User group User name -g groupCopy the code

Changing a User password

Passwd usernameCopy the code

Adding a User Group

Groupadd user groupCopy the code

View the user group of the current user

groups
Copy the code

Delete user

Userdel-rf User nameCopy the code

Switch the user

Su user nameCopy the code

permissions

D RWX r-x r-x \ -rw-r -- r Folder, represent the type of file, d - indicates a file 2. RWX, r to write readable, w, x executable file owner permissions on this file 3 r - x (no write access to the rest of the same user group, readable and executable permissions), the same user group of the other user permissions on this file. R -x (Users in other user groups have only the read and execute permissions.) Permissions of users in other user groups Common file Owner permission Of users in other groups Permission of users in other groups -- three short lines indicate read r, write W, and execute X, for example: RWX or rw- Modify file permissions chmod 777 File name First 7: indicates the owner of the current file, with read, write, and execute permissions second 7: indicates the owner of the current file, with read, write, and execute permissions third 7: indicates the owner of the current file. Other groups of people, have read, write, and execute permissions the numbers are expressed as follows: r=4 w=2 x=1 -=0 \ -rw-RW-r -- the first one - : indicates whether this is a file or folder - indicates a file, d indicates a folder The second Rw - : indicates the permissions for the current file owner: R can read w can write At last - there are two values, respectively - and x, x stands for an executable, - said unenforceable Third, rw - said for the current file owner in terms of other users in the same user group, can read can write permissions The fourth r, : said other users in the group user permissions, only can read permissionCopy the code

HelloWorld for Shell scripting

Name ="hengge"; hellowrold. echo $name; 2. Grant executable permission to the sh file chmod +x helloWorld. sh 3Copy the code

conclusion

These commands need a lot of practice to become familiar with, of course, There are many Linux commands, if you need to use it, you can go to the Internet to check. Later we will show you how to configure the Linux network.Copy the code

If you need to learn more about Java, click here for a more detailed summary of Java knowledge