In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to use linux shell command line parameters". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
It is customary to use the linux command line to manage the linux system, for example:
The code is as follows:
$date
2 11 23 01:34:58 CST 1999
$
When the user logs in, he actually enters the shell, which follows a certain syntax to interpret the input commands and pass them to the system.
The first word entered on the command line must be the name of a command, the second word must be the option or parameter of the command, and each word on the command line must be separated by a space or TAB in the following format:
The code is as follows:
$Command Option Arguments
One, options and parameters
An option is code that includes one or more letters, preceded by a minus sign (a minus sign is necessary, which Linux uses to distinguish between options and parameters), and options can be used to change the type of action performed by the command. For example:
The code is as follows:
$ls
Motd passwd
This is a non-optional ls command that lists all the files in the current directory, listing only the names of each file, and showing no more information.
The code is as follows:
$ls-l
Total 2
-rw-r--r-- 2 wzh book 22 Apr 20 20:37 motd
-rw-r--r-- 2 wzh book 796 Apr 20 20:37 passwd
Adding the-l option will list a row of information for each file, such as the data size and when the data was last modified.
Most commands are designed to accept parameters. Parameters are one or more words typed after the option on the command line, for example:
The code is as follows:
$ls-l text
-rw-r--r-- 2 wzh book 22 Apr 20 20:37 motd
-rw-r--r-- 2 wzh book 796 Apr 20 20:37 passwd
$
All files in the text directory and their information are displayed.
Some commands, such as ls, can take parameters, while others may require a minimum number of parameters. For example, the cp command requires at least two parameters, and if the number of parameters does not match the command requirements, shell will give an error message. For example:
The code is as follows:
$cp-i mydata newdata
Note: options on the command line precede parameter input.
Second, command line features
The command line is actually a text buffer that can be edited, and the entered text can be edited before pressing enter. For example, the back key can be used to delete the characters just typed, delete the whole line, and insert characters, so that if the user enters a command, especially a complex command, if there is a typing error, there is no need to re-enter the whole command, as long as the editing operation is used to correct the error.
The up arrow allows you to redisplay the command you just executed, and this feature allows you to repeat a previously executed command without having to retype it.
Bash keeps a list of previously typed commands, which is called a command history table. Press the up arrow to display each command one by one on the command line. Similarly, press the down arrow to move down in the command list so that previous commands are displayed on the command line, and you can modify and execute them. This feature will be discussed in detail in Section 10.4.
Multiple commands can also be placed on a command line, separated by semicolons. For example:
The code is as follows:
$ls-Finto cp-i mydata newdata
You can also enter a command on several command lines and continue one command line to the next line with a backslash.
The code is as follows:
$cp-I /
Mydata /
Newdata
The above cp command is entered in three lines, the first two lines ending with a backslash, and the three lines as one command line.
Special characters in shell
In addition to ordinary characters, some special characters with special meanings and functions can be used in shell. Attention should be paid to their special meaning and scope when using them. These special characters are introduced below.
Third, wildcard characters
Wildcards are used for pattern matching, such as file name matching, path name search, string lookup, and so on. The common wildcards are *,? And the character sequence enclosed in square brackets []. The user can include these wildcards in the file name as a command parameter to form a so-called "pattern string" that enters the line pattern matching during execution. The slash (/) must explicitly match. For example, "*" does not match .file, while ".*" can match .file.
? Represents any single character.
[] represents a specified range of characters, and as long as the character at the [] position in the file name is within the range specified in [], the file name matches the pattern string. The range of characters in square brackets can be composed of characters given directly, or by a starting character, an ending character, and a hyphen (-) in the middle. For example, f [a-d] has the same effect as f [abcd]. Shell will take all the file names that match the pattern string specified on the command line as arguments to the command to form the final command before executing the command.
The specific meaning of these wildcards.
Fourth, pattern string meaning
The code is as follows:
* the names of all files in the current directory.
* the name of the file containing Text in all file names in the current directory of Text*.
[ab-dm] * the names of all files starting with a, b, c, d, m in the current directory.
[ab-dm]? The name of all files in the current directory that begin with a, b, c, d, m and followed by only one character.
/ usr/bin/?? The name of all files with two-character names under the directory / usr/bin.
Note that the hyphen "-" is valid only in square brackets, indicating a range of characters, such as a normal character outside the square brackets. And * and? Only outside the square brackets are wildcards, if they appear in square brackets, they also lose the ability of wildcards and become ordinary characters. For example, in the pattern "- a [*?] abc", only one square bracket is a wildcard, * and? Are ordinary characters, so the strings it matches can only be-a*abc and-a?abc.
Finally, I will explain some problems that need to be paid attention to when using wildcards. Because of *,? And [] have a special meaning for shell, so these characters should not appear in normal file names. In particular, do not appear in the directory name, otherwise the Shell match may be infinitely recursive. It is also important to note that if there is no file name in the directory that matches the specified pattern string, Shell will use the pattern string itself as an argument to the relevant command. This may be why special characters appear in the command.
Five, quotation marks
There are three types of quotation marks in shell: single quotation marks, double quotation marks and back quotation marks.
Six, single quotation marks'
Characters enclosed in single quotation marks appear as normal characters. After special characters are enclosed in single quotation marks, they will also lose their original meaning and will only be interpreted as ordinary characters. For example:
The code is as follows:
$string='$PATH'
$echo $string
$PATH
It can be seen that $retains its own meaning and appears as an ordinary character.
Seven, double quotes. "
Characters enclosed in double quotation marks are still treated as ordinary characters except $, /,', and ", which are still special characters and retain their special functions. In the case of $, the variable and $are replaced with the value of the variable specified later; for /, it is an escape character, which tells shell not to treat the character after it specially, just as a normal character. As you can imagine, the only characters that need to be preceded by / in double quotation marks are $, /, 'and "itself. For the "sign, if it is not preceded by a /, Shell will match it with the previous" sign.
For example, suppose the value of PATH is.: / usr/bin:/bin, enter the command:
The code is as follows:
$TestString= "$PATH///" / $PATH "
$echo $TestString
.: / usr/bin:/ bin/ "$PATH
You can try not to add / before the second double quotation mark.
Eight, backquotation marks
The key corresponding to this character is usually located in the upper left corner of the keyboard and should not be confused with single quotation marks ('). The string enclosed in backquotes is interpreted by shell as a command line, and when executed, shell first executes the command line and replaces the entire backquote (including two backquotes) with its standard output. For example:
The code is as follows:
$pwd
/ home/xyz
$string= "current directory is `pwd`"
$echo $string
Current directour is / home/xyz
When shell executes the echo command, it first executes the command pwd in `pwd`, and replaces the output result / home / xyz with `pwd`, and finally outputs the whole result after replacement.
This function of backquotation marks can be used to carry out command substitution, that is, the execution results enclosed in backquotes can be assigned to specified variables. For example:
The code is as follows:
$today= `date`
$echo Today is $today
Today is Mon Apr 15 16:20:13 CST 1999
Backquotes can also be used in nesting. Note, however, that when nesting is used, the inner backquotation marks must be escaped with a backslash (/).
For example:
The code is as follows:
$abc= `echo The number of users is / `who | wc-l/ ``
$echo $abc
The number of users is 5
Special characters of shell can also be used on the command line between backquotes. In order to get the result of the command in ``, Shell actually executes the command specified in``. When executed, special characters in the command, such as $, ",?, etc., will have a special meaning, and ``can contain any legal Shell command, such as:
The code is as follows:
$ls
Note readme.txt Notice Unix.dir
$TestString= "`echo $HOME ``ls [nN] * `"
$echo $TestString
/ home/yxz note Notice
That's all for "how to use linux shell command line arguments". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.