Backend Prerequisites for Linux knowledge

Source: Internet
Author: User
Tags chmod readable temporary file storage zookeeper

    • Directory
      • Start with understanding the operating system
        • Operating system Introduction
        • Simple classification of operating systems
      • On Linux
        • About Linux
        • Introduction to the Birth of Linux
        • Classification of Linux
      • Linux File System Overview
        • Introduction to Linux file systems
        • File types and directory structure
      • Linux basic commands
        • Directory Switching commands
        • Operation commands for directories (add and revise)
        • Operation commands for files (add and revise)
        • Action commands for compressing files
        • Permissions command for Linux
        • Linux User Management
        • Management of Linux System user groups
        • Other common commands

Before learning Linux, let's start with an easy-to-understand operating system.

One starting from the understanding operating system 1.1 operating system introduction

I introduced what operating system by the following four points:

    • The operating system (Operation system, or OS) is the program that manages the computer hardware and software resources, and is the kernel and cornerstone of the system.
    • The operating system is essentially a software program running on a computer;
    • To provide users with an interface to interact with the system;
    • The operating system is divided between the core and the shell (we can understand the shell as an application around the kernel, and the kernel is the program that can operate the hardware).

1.2 Simple classification of operating systems
    1. Windows: Currently the most popular personal desktop operating system, not a long introduction, we all know.
    2. Unix: The oldest multi-user, multitasking operating system. According to the classification of operating system, it belongs to the time-sharing operating system. Unix is mostly used in servers, workstations, and now also on personal computers. It plays a very important role in creating the Internet, computer network, or client/server model.
    3. Linux: Linux is a set of free-to-use and free-to-propagate Unix-like operating systems. Linux has many different Linux versions, but they all use the Linux kernel . Linux can be installed in a variety of computer hardware devices, such as mobile phones, tablets, routers, video game consoles, desktops, mainframes, and supercomputers. Strictly speaking, the word Linux itself only represents the Linux kernel, but in fact people have become accustomed to using Linux to describe the entire Linux kernel, and use the GNU engineering various tools and databases of the operating system.

A brief discussion on Linux2.1 Linux Introduction

We've introduced Linux above, and we're only emphasizing three points here.

    • Unix-like systems: Linux is a free, open-source Unix-like operating system
    • Linux kernel: strictly speaking, the word Linux itself only represents the Linux kernel
    • The father of Linux: a legendary figure in the field of programming. He was the earliest author of the Linux kernel, then launched the Open Source project, serving as the top architect and project coordinator for the Linux kernel, one of the most famous computer programs and hackers in the world today. He also launched the open source project for Git and is the main developer.

Introduction to the birth of 2.2 Linux
    • In 1991, Linus Torvalds, a Finnish amateur computer enthusiast, wrote a system similar to Minix (a micro-kernel-based UNIX-like operating system) that was named by the FTP administrator as Linux to join the Free Software Fund's GNU program;
    • Linux with a lovely penguin as a symbol, symbolizing the aggressive, love life.
2.3 Linux Categories

Linux is divided into two types based on its native level:

    1. kernel version: Linux is not an operating system, strictly speaking, Linux is only a kernel in an operating system. What is the kernel? The kernel establishes a platform for communication between computer software and hardware, and the kernel provides system services such as file management, virtual memory, device I/O, etc.
    2. Release : Some organizations or companies have two development and re-released versions based on the kernel edition. There are many types of Linux distributions (Ubuntu and CentOS are used for many, beginners are recommended to choose CentOS), as shown in:
Three Linux file system Overview 3.1 Linux File system introduction

In the Linux operating system, all resources managed by the operating system, such as network interface cards, disk drives, printers, input, normal files, or directories, are considered to be a file.

This means that there is an important concept in Linux systems: Everything is a file . In fact, this is a manifestation of Unix philosophy, and Linux is to rewrite Unix, so this concept has been passed down. In UNIX systems, all resources are treated as files, including hardware devices. The UNIX system sees each hardware as a file, often called a device file, so that users can access the hardware in a way that reads and writes files.

3.2 File types and directory structure

Linux supports 5 types of files:

The directory structure of Linux is as follows:

The structure of the Linux file system is distinct, like an inverted tree, the topmost of which is its root directory:

Common Directory Description:

  • /bin: store binary executable (Ls,cat,mkdir, etc.), common commands are usually here;
  • / etc: storage System Management and configuration files;
  • /home: The root directory of all user files is the base point of the user's main directory, such as the user's home directory is/home/user, can be expressed by ~user;
  • /usr: for storing system applications;
  • /OPT: the location where additional installed optional application packages are placed. In general, we can install Tomcat and so on here;
  • /proc: Virtual file system directory, which is a mapping of system memory. This directory can be accessed directly to obtain system information;
  • /root: home directory for Superuser (System administrator) (privileged class ^o^);
  • /sbin: The binary executable file is stored and can only be accessed by root. The system-level administrative commands and programs used by the system administrator are stored here. such as ifconfig and so on;
  • /dev: for storing device files;
  • /mnt: The system administrator installs the temporary file system installation point, the system provides this directory is lets the user temporarily mounts other file system;
  • /boot: store various files used for system boot;
  • /lib: storage and system operation related library files;
  • /tmp: used for storing various temporary files, is a common temporary file storage point;
  • /var: used to store files that need to change data at run time, as well as overflow areas of some large files, such as log files for various services (System boot log, etc.). such as
  • /lost+found: This directory is usually empty, the system is not properly shutdown and left "homeless" files (what is called under Windows. chk) right here.
Four Linux basic commands

Here are just a few of the more commonly used commands. Recommend a Linux command quick check site, very good, if you forget some commands or do not understand some commands can be resolved here.

Linux command Daquan: http://man.linuxde.net/

4.1 Directory switching commands
    • cd usr : switch to the USR directory under this directory
    • cd ..(或cd../) : switch to the previous level directory
    • cd / : switch to the system root directory
    • cd ~ : switch to User home directory
    • cd - : switch to the previous directory
4.2 Operational commands for directories (additional deletions)
  1. mkdir 目录名称 : Add Directory
  2. ls或者ll(ll is ls-l abbreviation, ll command to see all directories and files in this directory for more information): View directory information
  3. find 目录 参数 : search directory (check)

    Example:

    • List all files and folders in the current directory and subdirectories:find .
    • /homeunder directory, look for filenames ending in. txt:find /home -name "*.txt"
    • Ditto, but ignoring case:find /home -iname "*.txt"
    • Find all files ending in. txt and. pdf under the current directory and subdirectories: find . \( -name "*.txt" -o -name "*.pdf" \) orfind . -name "*.txt" -o -name "*.pdf"
  4. mv 目录名称 新目录名称 : Modify the name of the directory (change)

    NOTE: The MV syntax can be renamed not only to directories but also to various files, compressed packages, and so on. The MV command is used to rename a file or directory, or to move a file from one directory to another. Another use of the MV command is described later.
  5. mv 目录名称 目录的新位置 : Move Directory Location---cut (change)

    NOTE: The MV syntax can not only cut the directory, but also perform clipping operations on files and compressed packets. In addition MV and CP results, MV as if the file "move", the number of files did not increase. The CP file is copied and the number of files is increased.
  6. cp -r 目录名称 目录拷贝的目标位置 : copy directory (change),-R for recursive copy

    Note: The CP command can not only copy directories but also copy files, compress packages and so on, copy files and compress packages without writing-R recursion
  7. rm [-rf] 目录 : Deleting a directory (delete)

    Note: RM can not only delete directories, but also delete other files or compressed packages, in order to enhance the memory of everyone, regardless of the deletion of any directory or files, directly using the rm -rf directory/File/compression Package

4.3 Operation commands for files (add and revise)
  1. touch 文件名称 : creation of files (increase)
  2. cat/more/less/tail 文件名称File View (check)
    • cat : only the last screen content can be displayed
    • more : The percentage can be displayed, the carriage return can be one line down, the space can be a page down, Q can exit view
    • less : You can use PgUp and PgDn on the keyboard to page up and down, Q end view
    • tail-10 : View the following 10 lines of the file, CTRL + C end
    Note: The command tail-f file can dynamically monitor a file, such as Tomcat's log file, which will change as the program runs, and can use tail-f catalina-2016-11-11.log to monitor file changes
  3. vim 文件 : Modify the contents of the file (change)

    Vim Editor is a powerful component of Linux, is a strong version of the VI editor, VIM Editor commands and shortcuts have a lot of, but here do not elaborate, we do not have to study very thorough, using VIM to edit the way the file is basically used.

    In actual development, the main function of using the VIM editor is to modify the configuration file, the following are the general steps:

    Vim file------> enter file-----> Command mode------> Press I to enter edit mode-----> Edit File-------> Press ESC to enter bottom line mode-----> Input: wq/q! (Input Wq means write and exit, save; input q! represents force quit. )
  4. rm -rf 文件 : deleting files (delete)

    Same directory Delete: memorize rm -rf files can

4.4 Operation commands for compressed files

1) package and compress the file:

Packaged files in Linux generally end in. tar, and compressed commands typically end in. gz.

In general, packaging and compression are carried out together, packaged and compressed files with the suffix name. tar.gz.
Command:tar -zcvf 打包压缩后的文件名 要打包压缩的文件
which

Z: Call the gzip compression command to compress

C: Packaging files

V: Show the running process

F: Specify file name

For example: Add the test directory with three files are: Aaa.txt bbb.txt ccc.txt, if we want to package the test directory and specify the compressed package name for test.tar.gz can use the command: tar -zcvf test.tar.gz aaa.txt bbb.txt ccc.txt or: tar -zcvf test.tar.gz /test/

2) Unzip the package:

Command: Tar [-XVF] Compressed file

Where: x: Representative Decompression

Example:

1 Extract the test.tar.gz under/test to the current directory to use the command:tar -xvf test.tar.gz

2 Extract the test.tar.gz under/test to the root directory/usr: tar -xvf xxx.tar.gz -C /usr (-C for the location specified for decompression)

4.5 Permissions command for Linux

Each file in the operating system has specific permissions, the owning user, and the owning group. Permissions are the mechanisms used by the operating system to restrict access to resources, and in Linux the permissions are generally divided into read (readable), write (writable), and execute (excutable), divided into three groups. The respective owner (owner) of the file, belonging to the group and other users (other), through such a mechanism to restrict which users, which groups can do what the specific files do. by ls -l Command We can view the permissions of a file or directory under a directory

Example: in a random directoryls -l

The information for the first column is explained as follows:

The following is a detailed explanation of the type of file, permissions in Linux, and what is the owner, group, and other group of files?

Type of File:

    • D: Representative Directory
    • -: Representative file
    • L: Represents a link (can be considered a shortcut in window)

The permissions in Linux are divided into the following categories:

    • R: The delegate permission is readable, R can also be represented by the number 4
    • W: Delegate permission is writable, W can also be represented by the number 2
    • X: The delegate permission is executable, X can also be represented by the number 1

Differences in file and directory permissions:

Read-write execution represents a different meaning for files and directories.

For files:

Permission Name executable Operation
R You can use Cat to view the contents of a file
W Can modify the contents of a file
X You can run it as a binary file

For directories:

Permission Name executable Operation
R You can view the following tables in the catalog
W Can create and delete files under directory
X You can use the CD to enter the directory

Each user in Linux must belong to a group and cannot be independent of the group. In Linux, each file has the concept of owner, group, and other groups.

    • Owner

      Typically, the creator of the file, who created the file, naturally becomes the owner of the file, and with the Ls‐ahl command you can see that the owner of the file can also modify the file owner by using the Chown user name file name.
    • The group where the files are

      When a user creates a file, the group in which the file is located is the group that the user is in with the Ls‐ahl command to see all the groups of the file, and the CHGRP group name file name can be used to modify the group that the file resides in.
    • Other groups

      Other users of the system are other groups of files, except for the owner of the file and the user in the same group

Let's take a look at how to modify the file/directory permissions.

Commands to modify permissions for a file/directory:chmod

Example: Modify the permissions of the Aaa.txt under/test to have all permissions for the owner, the group that belongs to the host has read and write permissions,
Other users have read-only permissions

chmod u=rwx,g=rw,o=r aaa.txt

The above example can also be represented using a number:

chmod 764 Aaa.txt

To add a more common thing:

If we have a zookeeper, how do we do it every time we turn it on and ask for it to start automatically?

    1. Create a new script zookeeper
    2. To add executable permissions for the newly created script zookeeper, the command is:chmod +x zookeeper
    3. To add the zookeeper script to the boot entry, the command is:chkconfig --add zookeeper
    4. To see if you want to add success, the command is:chkconfig --list
4.6 Linux User Management

Linux system is a multi-user multi-tasking time-sharing system, any user who wants to use system resources must first request an account from the system administrator and then enter the system as this account.

On the one hand, the user's account can help the system administrator to track the users who use the system and control their access to system resources, and on the other hand can help users organize files and provide security protection for users.

Linux User Management related commands:

    • useradd 选项 用户名: Add user account
    • userdel 选项 用户名: Delete a user account
    • usermod 选项 用户名: Modify Account
    • passwd 用户名: Change or create a user's password
    • passwd -S 用户名: Displays user account password information
    • passwd -d 用户名: Clear User Password

The Useradd command is used for new system users created in Linux. Useradd can be used to create user accounts. After the account is built, then use passwd to set the password of the account. You can delete an account by using Userdel. The account number created by using the USERADD directive is actually saved in the/etc/passwd text file.

The passwd command sets the user's authentication information, including the user's password, password expiration time, and so on. The system administrator can use it to manage the password of the system user. Only the manager can specify the user name, the general user can only change their own password.

4.7 Management of Linux system user groups

Each user has a user group, and the system can centrally manage all users in a single user group. Different Linux systems provide a different set of user groups, as users under Linux belong to a user group with the same name, which is created at the same time as the user is created.

The management of user groups involves adding, deleting, and modifying user groups. The addition, deletion, and modification of a group is actually an update to the/etc/group file.

Management-related commands for Linux system user groups:

    • groupadd 选项 用户组: Add a new user group
    • groupdel 用户组: To delete an existing user group
    • groupmod 选项 用户组: Modify the properties of a user group
4.8 Other common commands
    • pwd : show Current location
    • grep Search for a string of files--color : strong> Search Command,--color represents highlighting
    • ps-ef / PS aux : Both commands are to view the current system running process, and the difference is that the presentation format is different. If you want to see a particular process you can use this format: PS aux|grep redis (view processes including Redis strings)

      Note: If you are using PS directly (process Status) command, which displays the state of all processes, usually in conjunction with the grep command, to see the status of a process.
    • pid of the kill-9 process : Kill Process (-9 indicates forced termination.)

      Use PS to find the process, and then kill it with kill
    • network communication command:
      • View current system NIC information: Ifconfig
      • View connection to a machine: pin G
      • To view the port usage for the current system: Netstat-an
    • shutdown : shutdown-h now : Specify to shut down now immediately; shutdown +5 "System will shutdown after 5 minutes" : Specify 5 minutes after the shutdown and send a warning message to the logged in user.
    • reboot : reboot : reboot. reboot-w : do a reboot (only the record does not really reboot).

Prerequisites for back-end Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.