In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what skills to use Bash in linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Introduction to BASH function
1. Command history
Bash has the function of automatically recording the history of commands, and commands executed by users will be automatically recorded in a hidden file such as. Bash_history in their home directory when logging out. There are many ways to view the history of these commands, including by opening the file directly, flipping the history up or down through the up and down keys of the keyboard, and viewing the history through the history command, all of which have record numbers. The amount of information that can be recorded in the command history is determined by the HISTSIZE variable. CentOS 6.3 defines HISTSIZE=1000 by default through the / etc/profile file, that is, it can record up to 1000 commands that have been used recently. When the 1001 command is executed, the * command will be overwritten. Executing the history-c command can clear all history records.
Those who record the history of the command can not only view the history, but also directly call the history to execute the command again when needed:
1)。 The arrow keys flip through the history command, find the appropriate command and then enter directly to execute it.
2)。 Enter! string invokes command history (string is the keyword). For example,! vim will call * * commands that begin with vim. Or through! n to accurately locate the history, for example! 242 will directly call the command history of the 242 record and execution.
3)。 Open the search function through the Ctrl+r shortcut key, and then enter the keyword to search for relevant commands in the command history, and enter to complete the operation. If no suitable command is found, press ESC to exit the search.
two。 Command alias
In the CentOS 6.3system, we can directly use the ll command to display the details of the file, in fact, there is no such a command in the system, it is only an alias defined in advance, the advantage of aliases is that it can simplify the abbreviation of long instructions, aliases for commonly used and complex commands and options can greatly improve daily work efficiency.
3. Piping and redirection
The standard input devices of Bash are keyboards, mice, handwriting boards and other devices, and the standard output is the display. Generally, we enter commands through the keyboard and execute them, and the system displays the returned information on the screen. By default, whether it is correct or wrong, the information will be output to the display. The file descriptor for standard input is 0, for standard output is 1, and for error output is 2. But sometimes we need to change the standard input and output mode. In Linux, we can use redirects (, |) to redefine input and output.
The pipe allows us to connect multiple commands together, and its function is to redirect the standard output of one command to the next command as standard input to that command. For example, if you use the ifconfig eth0 | grep 'inet addr' command to filter lines containing IP addresses, ifconfig itself will output a large amount of information about the network interface. Because the pipe symbol (|) is used here, all the output of the ifconfig command will be used as the input of the grep command, and finally the lines containing IP addresses will be filtered.
The standard output information is output to the monitor, and sometimes you may not need the output information, or you may not need to see it on the screen for the time being; in addition, the input information is usually entered through the keyboard, and sometimes you may want to be able to read the input information from the file. Output redirection can use the > or > > symbol, use > to import the output to a file, create the file if the file does not exist, and overwrite the contents of the file if the file already exists; and use > > to append the output to the file; in addition, the redirection of the corresponding error message needs to be implemented using the 2 > or 2 > > symbol. Input redirection can be done using / dev/null & & echo "Hi,tom" | | echo "No such user"
Example 5 first masks all the output of the id command with the & > redirector, and then uses & & and | | to determine whether the id command is executed successfully. If it succeeds, it displays a greeting, otherwise it shows that there is no such user.
3. Job control
In the Bash environment, you can use the & symbol to enable the process to enter the background to execute, or use the Ctrl+z shortcut key after the execution of a command to put the process into the background and suspend execution. Later, you can use the jobs command to view these background processes at any time, and each such process will be assigned a number, and these background processes can be called back to the foreground to execute again in the form of fg.
[root@centos6 ~] # firefox & [root@centos6 ~] # jobs [1] + Running firefox & [root@centos6 ~] # fg 1
4. The use of curly braces {}
The string needed by the command line or script can be produced through the extension of parentheses. Parentheses can contain consecutive sequences or multiple items separated by commas, consecutive sequences including a starting point and an end point and using.. Split. Next, let's take a look at specific examples of grammatical formats:
The above is all the content of the article "what are the tips for using Bash in linux?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.