Linux commands are commands for managing Linux systems
For the Linux system, whether it is a central processing unit, memory, disk drive, keyboard, mouse, or user, it is a file (everything is a file), and the commands for Linux system management are the core of its normal operation.
There are two types of linux commands in the system: built-in Shell commands and Linux commands
One, Linux command basis
In the Linux system, any string entered in the character operation interface that can complete a specific operation and task can be called a "command"
Strictly speaking, "command" usually only represents the name of an instruction or program that realizes a certain function
1.Shell overview
The execution of Linux commands must rely on the Shell command interpreter
User: The interface where we enter commands
The shell is actually a special program that runs in the Linux system. It acts as a "translator" between the user and the kernel. It is responsible for receiving and interpreting commands entered by the user, and translating the operations that need to be performed (translated into binary computer language ) Passed to the system kernel for execution
When the user logs in to the Linux system, the Shell program will be automatically loaded to provide the user with an operating system that can enter operating commands
Bash is the shell program used by default in the Linux system, and the file is located in /bin/bash
Kernel: It is the most critical component of the Linux operating system. It executes the translated commands and is used to implement core operations such as CPU and memory allocation, process scheduling, and device drivers. It is mainly hardware-oriented
2. Classification of Linux commands
2.1 The difference between internal commands and external commands
According to the relationship between Linux commands and Shell programs, generally divided into the following two types
Internal command
External instructions
Some special instructions integrated in the Shell interpreter program (such as Bash)
Script files or binary files that can complete specific functions in the Linux system
Part of Shell
Commands outside of the Shell interpreter program
There is no separate corresponding system file
Each external command corresponds to a file in the system
Automatically load memory, no need to re-read files from the hard disk, users can use it directly
The Linux system must know the file location corresponding to the external command before it can be loaded and executed by Shell
Linux defaults to adding directories for storing external commands and programs (such as /bin, /usr/bin, /usr/local/bin, etc.) to the user's "search path". When using external commands located in these directories, the user No need to specify a specific location, easy to use and increase efficiency
In most cases, there is no need to deliberately distinguish between internal commands and external commands. The method of use is similar.
2.2 The format of the Linux command line
When using internal or external commands, refer to a general command line format to use the format, which can facilitate understanding of the role and working mode of the Linux command line
General command line format: command word [option] [parameter]
Linux commands (including file names, etc.) are case sensitive, that is to say, if the command you enter is not the right case, the system will not respond as you expect, so English should be case-sensitive
In the actual use of the Linux command line, the terms "option" and "parameter" are often confused, and even the order is allowed to be reversed, but generally does not affect the execution effect of the command, so in many cases, strict distinction is not made.
2.2.1 Command word
The command word is the command name, which is the most critical part of the entire command
The only way to determine a command is to ensure that the input is correct, such as capitalization, etc. The operation is performed, such as new creation, deletion, renaming, etc.
2.2.2 Options
The role of the option is to adjust the specific function of the command and determine how the command is executed
Short format options: generally use the "-" symbol to guide the options, such as "-" multiple single-character options can be combined together, such as "-al" is equivalent to "-a -l"
Long format options: When using multiple-character options, generally use the "–" symbol to guide the options, such as "–help"
The long format options have clear meanings and are easy to remember. The short format options have a simple structure and quick input, and the two formats can be mixed
If the option is not used, the default function of the command word will be executed
2.2.3 Parameters
Command word processing object
It can be a file name, directory (path) name, or user name, etc.
According to the different command words used, the number of command parameters can be zero or more
3. Edit the Linux command line
When editing Linux commands, you can use the following auxiliary operations to improve input efficiency
3.1 Auxiliary operations for editing the Linux command line
button
effect
Tab 键
Automatic completion (command word, file or directory), press twice, the system will output the available list
Backslash "\"
If the input line of command is too long, the terminal will automatically wrap the line. Sometimes in order to display beautifully and facilitate viewing, you can use "\ forced line break (Note: Tab may not be possible), and continue typing after the ">" prompt that appears in the next line (+ Space+\) as a continuation of the previous line
Ctrl+U
Empty to the beginning of the line
Ctrl+K
Empty to the end of the line
Ctrl+L
Clear screen
Ctrl+C
Cancel this command edit
Ctrl+a
Switch to the beginning of the line
Ctrl+e
Switch to end of line
3.2 Command line prompt characters
例:[root@localhost~]#
root: the user currently logged in to the system
@: Separator
localhost: host name
~: The current directory
#: means login as an administrator ($: means login as an ordinary user)
Two, Linux command help
1 Overview
help provides help for internal commands
man or info provide help for external commands
If your English is good enough, you can be proficient in linux without relying on anyone, as long as you can use man
Man is actually the help for viewing instruction usage. The most important thing to learn any UNIX operating system is to learn to use the auxiliary command man
man is the abbreviation of manual (manual), its description is very detailed, but because it is all in English, it looks very headache
It is recommended that you see man again when you need it. Normally, just remember some basic usage.
2. Use the help command
The help command is a built-in command in Linux Shell, its purpose is to view the help information of the command inside the Shell
When using the help command, you only need to add the name of the internal command as a parameter
For example: directly enter the "help pwd" command to view the help information of the shell internal command pwd (the pwd command is used to display the working directory of the current user)
For most Linux external commands, you can use a general command option "- -help" to display the format and options of the corresponding command word and other help information
If the command word does not have the "- -help" option, generally only a simple command format will be prompted
For example: enter the "ls --help" command to view the help information of the ls command (the ls command is used to display file or directory listing information)
[root@localhost ~]# ls --help
用法:ls [选项]... [文件]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
-a, --all 不隐藏任何以. 开始的项目
-A, --almost-all 列出除. 及.. 以外的任何项目
--author 与-l 同时使用时列出每个文件的作者
......//省略部分内容(太多了,可以自己再打一遍慢慢看)
3. Use the man page
The manual page (Manual Page) is the most commonly used form of online help in Linux systems. Most of the external software provides detailed help manual pages for executing programs and configuration files during installation.
The information in these manual pages is organized in a characteristic format and read through a unified manual page browser program man
For example: enter "man command" to view the manual page information of the entered command (a lot, it's really special to see in detail, it will not be listed here)
When reading the man page, it will be displayed in full-screen text mode, and an interactive operating environment is provided
button
Features
"↑" or "↓"
Scroll up or down a line of text
"Page up" and "Page Dowd (or space bar)"
You can page up or down to display
"Q" or "q"
Exit the reading environment of man pages
"/"键
Search content, such as "/-v" to find the help information of the "-v" option. If you find too much content, you can also press the "n" key or the "N" key to select downward and upward points respectively
3. Basic operations of directories and files
1. Display the current working directory-pwd
Show the user's current working directory location
Change the user's working directory to another location
format
Description
cd target location
Switch to target location
cd ~ (home directory)
If you do not specify the target location, switch to the current user's home directory (home directory)
cd
Same as above
cd -
Switch to the directory where you were before the last cd command was executed
Usually use the target location (folder path) to be switched to as a parameter
If the target parameter is not specified, it will switch to the current user's home directory (home directory) by default
The home directory is the default working directory after Linux users log in to the system
When expressing the location of a certain directory (or file) in the Linux operating system, two different forms can be used according to the starting directory it refers to, called absolute path and relative path
2.1 Absolute path
Specify the exact location of the file in the entire file system, there will be no ambiguity, starting from the root directory "/" of the file system
Because there is only one root directory in the Linux operating system, no matter which directory it comes from, using an absolute path can very accurately indicate the location of a directory (or file).
But if the path is long, the input will be more cumbersome
2.2 Relative path
Given by the context of the call (current location), the "/" symbol is not used at the beginning, so it is easier and more convenient to use
Relative paths mainly include the following forms:
Manifestations
Description
Use the directory name or file name directly
Indicates the location of subdirectories and files in the current working directory
Start with a period "."
Indicates that the current working directory is used as the starting point
Start with two periods "..."
Indicates to take the upper level directory (parent directory) of the current directory as the starting point
Start with "~Username"
Indicates that the home directory of the specified user is used as the starting point
2.3 Summary
Relatively speaking, the use of a relative path to indicate a directory (file) path is flexible and changeable, usually used to identify the location of a directory (file) "near" to the current directory
The absolute path is often used to indicate a relatively stable (not often changed) directory in the Linux operating system.
When choosing a relative path or an absolute path, you should choose according to the actual situation
3. List the contents of the directory -ls
Display the contents of the directory, including the relevant attribute information of subdirectories and files, etc. ls [Options] [Files or directories...]
3.1 Common options
Options
effect
-l
Display detailed information of files (directories)
##创建两个空文件,文件名分别为aa.txt和bb.txt
[root@localhost /]# touch aa.txt bb.txt
[root@localhost /]# ls
aa.txt boot home media proc sbin tmp
bb.txt dev lib mnt root srv usr
bin etc lib64 opt run sys var
##或
##touch {a,b}.txt
Use the "-type" search criteria to filter out files of a specified type. For example, find all folders (corresponding to type d) in the following directory, and ignore other types of files
The system administrator can also search based on the file owner (-user), that is, search based on whether the file belongs to the target user. For example, execute the following command to recursively search for files in the /var/ directory whose owner is the apache user
Find is a Linux command we commonly use, but we generally find it is not just a look, there will be further operations, at this time the role of exec is revealed
The -exec parameter is followed by the Linux command, which uses a semicolon ";" as the end symbol. Since the semicolon has different meanings in various systems, the backslash escape character "\" is added before the semicolon {} represents the file name found by the previous find
Example: The find command matches all ordinary files in the current directory, and uses the "ls -l" command in the "-exec" option to list them
[root@localhost ~]# find ./ -type f -exec ls -l {} \;