Fundamentals of Linux operating System (iii)--basic operation and getting help

Source: Internet
Author: User


The operating system we understand in the traditional sense actually refers to the kernel of the operating system, as well as the aggregation of a large number of functionally diverse applications built on it. So narrowly speaking, the operating system refers to kernel. Kernel masks The complex logic of the underlying hardware, virtualizing the hardware into more accessible and accessible resources, and provides a calling interface to the upper-level application to ensure that the application works properly and that it can access and use the hardware resources. In these applications, one type of application is very special, it is the user's access to the computer, is the operator to complete the interactive logon and interactive work of the basis of such an application, which we call the interface program, or users to access the interface program.


For Linux systems, there are a number of options available, namely:

GUI: Graphical user interface, which is what we often call graphical interface

CLI: command-line interface, which is what we often call a text interface or a character interface


In the enterprise production environment, in order to enable the server to provide more resources for customer service, but also in order to speed up the server configuration management speed, most of the time, we will choose the text Interface for command operation execution. Let's discuss some of the basic features and usage rules of the Linux system.


The first thing you have to understand is the philosophical thinking of Linux:

1, all documents, Linux almost all of the resources are abstracted into a file form to save and use, the benefit is to simplify and materialize complex data management;

2, by a number of functions of a single program, each small program function single, usually only do one thing, but must do well; Assemble small program to complete complex task;

3, as far as possible to avoid interaction with users, easy to implement automation tasks in a programmatic manner;

4, the use of plain text files to save the program configuration information;


So what's the file?

For Linux systems, if we have a lot of files, how should we organize them effectively?

If we have a warehouse where goods are stored, how can the goods be placed to save space? How can the goods be placed to be found immediately when we need them?

The first thing we need to do is to think about how to plan the storage of these goods as reasonably as possible.

There are usually two ways of doing this: flat and hierarchical.

From the point of view of the above example, the flat management means that all goods are placed in the same organizational structure, and they are horizontal. Since all goods are in the same flat structure, there is only one way to find the goods that meet the requirements-traversal. If you are lucky enough, maybe the first one is what we are looking for, and if it is unfortunate enough, it may not be found until the last. And on average, it's looking for half.

Hierarchical management means that the goods will be classified according to certain characteristics or characteristics of the goods we store, that each classification can continue to be classified according to the characteristics of two, and so on, can achieve very distinct structure stratification, so as to facilitate the rapid retrieval of information. For example, these goods, but there may be a number of classification standards, can be divided according to the volume, can be divided according to the weight, can be divided according to the use of the way, but also the shelf life can be divided, and so on. In short there are a lot of classification criteria, we choose from the classification criteria we need to achieve classification. The advantage of this classification is that it is possible to narrow down the scope of the search progressively.


The computer's external storage device contains a large number of files, hierarchically divided by specific criteria, and a hierarchy-based approach to managing the file is called a file system. This means that a file system is a hierarchical structure that organizes and manages computer files according to a standard or specification. In the file system, each file is represented by a directory. The directory exists primarily to implement path mappings. A file is a stream of data that is bounded on a disk and can be accessed by name.


These files are from the only original starting point-the root, expressed as "/", thus organized into an inverted tree structure. All files are started from the root, step by step to find the target file. In the process of locating the target file, the hierarchy of all the passed directories is called the path. This path is called an absolute path if it is from the root, and is called a relative path if it starts from the working directory. Throughout the path, only the leftmost first "/" represents the root directory, and the remaining "/" is simply a directory separator in the path, such as:/dev/pts/0.


Rules for using file names:

The naming of filenames is based on a file system, where the naming conventions of files may differ in different file systems. In CentOS, the default file system used for different distributions is not the same, as the CentOS6 series uses the Ext4 file system by default, whereas the CentOS7 series uses the XFS filesystem by default. Instead, the FAT or NTFS file system is used by default in Windows.

In the Linux ext4 or XFS file system, the file name has the following definitions and rules to use:

1. Case sensitivity (case sensitive)

2. The directory is also a file, in the same path, two files cannot have the same name

3. The file name can be any character except "/"

4. Maximum of 255 characters


These are the basic concepts of file and file systems.


As we said earlier, a complete operating system is composed of kernel+ applications. In other words, in addition to kernel this monitoring program, users need to have the functionality of the application provided. So, what are the components of a standard application software?

Generally speaking, application software running in Linux consists of the following four parts:

1. binary files

2. Header, library file

3. Help Files

4. Configuration files


Let's talk about how users use the operating system.


Before we start using the operating system formally, I'll introduce you to a few basic concepts:

Host directory: also known as home directory. After the user has been created, in general, a directory is created for each user, which is the place to save the user's private data, which is the home directory. Home directory is also the starting directory for users to log on to the system, which means that the directory is the default working directory of the shell opened after the user logs on. Typically, any user can create files in their home directory and manage those files.


working directory: the directory in which the shell is located when an operation or command is completed.


the path to any file consists of two parts: the base name and the file name

Base name: This is the file's own name.

Directory Name: is the cumulative name of all directories that go through the path of accessing the file in order to access the specified file

Such as:

/etc/sysconfig/network-scripts/ifcfg-eth0


Among them, Ifcfg-eth0 is the base name of this file, which is the real name of the file.

/etc/sysconfig/network-scripts is the directory name, which is the cumulative name of the directory that must be passed to find the file.


There are two commands to view the base and directory names for a given path:

BaseName: Gets the base name of the given file path

[Email protected] ~]# basename/etc/httpd/conf.d/welcome.conf welcome.conf

DirName: Gets the directory name of the given file path

[Email protected] ~]# dirname/etc/httpd/conf.d/welcome.conf/etc/httpd/conf.d/


A user who wants to use a computer and wants to use the Linux operating system to manage computer resources must have an identity that is certified as legitimate. Such authentication is done by identifying the user with a password that has been set up to secure the use of this identity. Only this information is correct, the user will be introduced to the system. The user is then granted the right to use the files and data in the system based on the user's identity.


Each user after the successful login, the system will start a default shell, this setting is generally stored in the/etc/passwd file;

Use the following command to view the shell currently being used by the user:

[Email protected] ~]# echo $SHELL/bin/bash


This/bin/bash is one of many command-line interfaces, and has been listed as a standard for use. By default, Linux assigns the shell to each user as its default shell. The Shell interface program can be started directly as long as the user has successfully logged on to the system through authentication. In other words, the user's next operation is done in this shell interface.


Well, we've probably noticed that after the login is successful, the system command returns such an interesting string as follows:

[email protected] ~]#

This is what we call "command prompt." All of our commands are completed at this prompt. In this default command prompt, we can see a lot of interesting information, we can put this thing into several points to illustrate, namely: root,localhost,~ and #.

Root: The login name of the currently logged-in user;

localhost: the host name of the current host's non-complete format, usually intercepted from the first '. ' Before, the full format is generally FQDN, if in the process of installing the system, we did not set the host name, its default value should be: localhost.localdomain;

~:The base name of the path to the non-full-format path of the shell program is actually a directory name, which we call the shell's working directory, and by default, the shell's working directory is the user's own home.

#: command Prompt symbol:

#: Administrator account, which is the root user, has the highest privilege, can perform all operations, almost not be limited by the operating system itself, so this account is also a very dangerous account, so the identity of the user must be strictly confidential, will have very serious consequences;

$: Ordinary users, that is, non-root users, do not have administrative rights, can not perform management class operations;

Note: In a production environment, it is recommended to log in to the Linux system using a non-root account, and if there is a need to perform administrative operations, you can temporarily switch to the root account (sudo, Su can) and exit immediately once the operation is complete.


The content of the command prompt, as described above, is just the user-provided content of bash. Some of the escape sequences we used to define with "\" can help us implement richer command prompt content. These are stored in bash's PS1 variable. View the escape sequences stored in the PS1 variable by default, which can be used as follows:

[[email protected] ~]# echo $PS 1 [\[email protected]\h \w]\$


The more commonly used escape sequences are:

\d use the format of the day of the month to display the system time, such as: Wed May 18

\h until the first one "." The previous host name

\h Full host Name

\j the number of background processes (jobs) currently managed by the Shell

\l The base name of the path to the terminal device file for the currently logged-in shell

The name of the \s shell, the base name of $

\ t identifies 24-hour time in HH:MM:SS format

\ t identifies 12-hour time in HH:MM:SS format

\u the user name of the currently logged on user

\w the absolute path representation of the current working directory

\w the base name of the absolute path to the current working directory

\! Number of the current command in the history command list

\# The current command is the first command executed since this login

\$ If the user's valid UID is 0, it will be displayed as #;


The use of these escape sequences allows us to enrich the command prompt for Linux. Interested small partners can try.


Next, let's take a look at the general syntax format for commands:

[[Email protected] ~]# command option parameter


Command:

Refers to what we need to do with the computer, such as managing files, managing users, etc. The shell program is a unique program that can find and parse commands, submit commands to the kernel and run them as processes, parse paths, provide an environment for automating command execution, and so on.

So how does the shell interpret the command and parse the path?

First, it's worth noting that the shell first divides the command into sections based on a specific delimiter (the default is a white space character) before executing a command. After that, the shell will think of the first part even if we want to execute the command. Later sections will be interpreted by the shell as options or parameters.


Second, when the command has been determined, the shell must determine how the command executes in order to execute the command. Therefore, you can classify the shell commands into the following two categories, from the way the commands are executed:

1. Internal command (Shell Builtin):

Commands that are brought in by the shell program, which are usually loaded into memory directly with the shell's loading, do not require disk IO when executing such commands, so they are highly efficient and fast, but often have fewer names, and each internal command is a very basic command.

2. External command:

An executable program file that exists independently of the external memory; Most applications provide functionality that relies on relative external commands.

Commands are usually executables, so-called executables are files that have been given execution permissions. However, not all files can be given execution permissions, nor are files that are assigned the Execute permission to be executables. What we say in this executable file, mainly refers to the following two categories, namely:

binary format program files;

Script files: Need to be interpreted by the interpreter to run;


The executable binaries that correspond to external commands are mostly found in directories such as/bin or/sbin. In RHEL6 and CentOS6, this kind of storage can be used to perform binary questions of the directory is more, such as:/bin,/sbin,/usr/bin,/usr/sbin, and in RHEL7 and CentOS7, the unified binary files are placed in the/usr /bin,/usr/sbin directory, but in order to ensure the compatibility of the root directory of the first-level subdirectory, created/bin and/sbin two symbolic links, respectively, linked to just two locations. In addition, if you need to compile the source code to install external applications, it is also possible to install the executable binaries into/usr/local/bin,/usr/local/sbin, and in the user's host directory may also exist ~/ The bin directory is used to save the binaries.

Finally, so many directories can be used to save executable binaries, so how does the shell find the path to the files corresponding to these external commands? In fact, in the shell there is a built-in environment variable named path, which holds the storage path of all the default available binaries, so when the shell discovers that the executable command is not an internal command but an external command, it finds the path in the path variable. Then find out if there is a corresponding file name in each path, and if so, execute it. However, if each execution of an external command needs to find its corresponding path in the path variable, it is inefficient, so the shell introduces the mechanism of the external command cache, all the successfully executed external command path will be temporarily cached in memory, A command that is not executed for the first time reads its path information directly from the cache. This cached information can be viewed using the following command:

[[email protected] ~]# Hash hits command 1/sbin/ifconfig 2/bin/touch 1/bin/mkdir 4 /bin/ls

So how do we tell if the order is internal or external?

In fact, we just need a simple command.

[[Email protected] ~]# type COMMAND

The result of this command can be in the following cases:

1. If the command being detected is an external command, the type displays a specific path, which is found by the path stored in the path variable;

2. If the command being instrumented is an internal command, the type command displays the message "command is Shell Buildin"

3. Of course there may be a third case, that is, in order to facilitate user use, it is possible to put a command and its common choice to build an alias command, so if this is the case, the type command will be the alias command and the original command, options and the combination of parameters display.

Options:

Adjusts the running characteristics of the command. In general, the result of command execution is relatively simple, and the result is not enough to meet our needs, this time we can use the option to enable the command can output more in line with the user requirements of the execution results.

In general, there are two types of options:

Short options:-char, e.g.,-l,-H,-D,... In most cases, multiple short options can be combined, such as:-LHD equivalent to-l-h-D three options;

Long options:--word, such as,--long,--human-readable, ... In most cases, multiple long options must be separated by white space characters, otherwise the command will not recognize these long options correctly and report an error message.

Note:

1. Some options can take parameters, called option parameters;

2. Once you have chosen to carry the parameters, the parameters of the options and options must be adjacent;

3. If you have more than one option to carry parameters, these options are not suitable for merging, regardless of length.

4. If there are options with parameters such as white space characters or other characters, such parameters must be quoted in quotation marks. such as:

[Email protected] ~]# ls-lhd/etc

[[email protected] ~]# useradd-d/home/user1-s/bin/bash-c ' Network Manager ' user1

Parameters:

The object of the command, depending on the meaning of the command, may be a different object. For example: path (relative path, absolute path), number or number combination, specific meaning of the string, and even some special functions of special characters, etc.

Attention:

1. Some commands or options can have multiple parameters, separated by whitespace characters between parameters;

2. Some commands or options can only write one parameter, if you write more than one parameter attempt to execute, the command will error;

3. While some commands or options support only one parameter, we can separate multiple parameters with specific characters, such as commas, to achieve the purpose of passing multiple parameters.

In the process of using Linux, we may be exposed to a lot of commands, but the Linux command is too many, and some commands are too complex, so many people can not do any command is familiar. Therefore, we can choose to ask for help when we encounter commands that are not or are useless. Of course, Linux has come up with this problem, so there are a number of ways to help us and a lot of help document information.


How do I get help with my command?

method One: Use the help command to get help information:

Internal command:

[[email protected] ~]# help COMMAND

External command:

1. command to bring the use of the brief format of help, but such an option is not every command, you should pay more attention to use;

[[email protected] ~]# COMMAND--help

2. Using the Man Help Manual (manual)

By default, we use the Package management tool to install the package of the compiled application directly into the Linux system, and when installing the application software, it installs the Help files needed by the software, the default storage location:/usr/share/man/

In the above directory, we can see a directory like this: Man1, man2, ..., man9, these directories are the different types of various applications of the Help file storage location, a total of 9 chapters of the content. These help files are stored in a compressed format, and when viewed, the less command is used to assist the display, so the operation is fully compliant with the less command's operation specification. Here's how:

Flip Screen:

Space, F: Turn a screen at the end of the file;

B: Turn the file to the first screen;

D: half-screen to the tail of the file;

U: Turn half screen to file header;

Enter: Flip a line to the end of the file;

Y,k: Flip a line to the file header;

G: Jump to the last line;

#G: Jump to Line #;

Keyword search:

/keyword: Search the tail of the file;

? KEYWORD: Search the file header;

N: The same direction as the search command;

N: Opposite to the search command direction;

Exit:

Q:quit


The nine chapters of the so-called man are saved with different help information. The specific content that corresponds to it refers to:

1. Executable program or BINARY command

2. System calls (interface functions provided by the kernel)

3.C Library Invocation (interface functions provided by the library)

4. Special files (usually referred to as device files)

5. Format and Convention specification for configuration files

6. Game-related

7. Miscellaneous (may contain a large number of packages and their specifications)

8. System administration commands (usually commands that can only be executed by the root user)

9. Kernel program [non-standard]

How to use man:

[email protected] ~]# man [OPTIONS] ... KEYWORD

After using the man command. What you see usually has a very standard format and structure, and each help file is developed this is divided into sections, which mainly include:

Name : title and brief function description;

Synopsis: command uses a format digest;

DESCRIPTION: Detailed description of the information;

Options : Detailed description of the option;

AUTHOR: author

BUGS: A way to report a bug in a program;

EXAMPLES: use example;

See ALSO: Additional references

files: the relevant configuration files;

The synopsis, which clearly describes the use of the command format and the combination of options, we usually see the following types of special symbols, their meaning is described as follows:

[]: Optional content;

{}: Grouping boundaries;

<>: Content that must be provided;

A|b|c: choose one more;

... : Similar content can appear multiple times;

Note:

1. The man command will find the user manual in many paths, which are the paths defined in the/etc/man_db.conf (CentOS7) or/etc/man_config (CentOS6) file using the "MANPATH" directive;

2. If the path is not included in the configuration file and we just want to use an extra path temporarily, you can use the following command:

[Email protected] ~]# man-m/path/to/somedir KEYWORD

The command means: Find the relevant keyword manual and output it to the specified path;

3) Info COMMAND

Get the online documentation for the command;


method Two: Bring your own Help document

Many applications bring their own help documents when they are installed, and these help documents are stored in the/usr/share/doc/application_name-version/directory, where Application_ Name-version refers to the application file name and its version number. In this directory, the following files are often useful:

1.README: Relevant information about the program;

2.INSTALL: Installation help for the program;

3.CHANGES: Update information for version iterations;


method Three: The document on the master station of the program

Such documents provide online Help in the right navigation bar of the http://nginx.org site:

1.document| Documentation

2.wiki

3.FAQ


method Four: Search engine--google

Keyword Filetype:type

Keyword Site:domain. Tld

This article is from the "home of the Ops" blog, so be sure to keep this source http://zhaotianyu.blog.51cto.com/132212/1775669

Fundamentals of Linux operating System (iii)--basic operation and getting help

Related Article

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.