Home > Operation and Maintenance > Safety > What are the basic features of bash

What are the basic features of bash

王林
Release: 2023-05-14 23:07:10
forward
1595 people have browsed it

#Command aliases of basic features of bash
In the shell process of bash, you can set aliases for the command itself or for the command plus options. After setting, you can directly enter the alias to call its function.
The way to set the command alias is: ~]# alias NAME=COMMAN.
The way to revoke a command alias is:~]# unalias NAME
The way to view the command alias that has been set in the current bash is:~]# alias
Note 1: The life cycle of the command alias set in this way Just the current shell process. Exiting the current shell and logging in again will no longer work. If you want it to take effect automatically after the shell starts, you need to set the bash environment variable related configuration file.
Note 2: If the command alias and the command name are the same, the function of the command defined by the alias is directly called. If you need to directly call the function of the command itself instead of an alias, you can use "~]# \COMMAND.

#Command history of basic features of bash
bash will be automatically saved in the shell process The commands that the user has executed in their session are stored in the memory space during the shell operation. When the shell process ends, the previously executed commands are persisted by storing them in the "history file". Each time the shell process starts, Read the contents of the file into the memory space. Each user has his own dedicated history file.
Variables of history-related parameters
HISTSIZE: The number of historical commands retained by the buffer of the SHELL process
~]# echo $HISTSIZE can check its size
~]# export HISTSIZE=# can set its size
HISTFILESIZE: The number of historical commands that can be saved in the command history file
~]# echo $HISTFILESIZE can View its size
~]# export HISTFILESIZE=# You can set its size
HISTFILE: Current user’s command history file
~]# echo $HISTFILE You can view the file name and address
HISTCONTROL: Current user record Command history method
~]# echo $HISTCONTROL can view the file name and address
~]# export HISTCONTROL=method name can set the method of recording command history
There are three methods:
ignoredups: ignore Repeated commands; repetition refers to consecutive and identical commands;
ignorespace: commands starting with a blank character are not recorded in the history;
ignoreboth: the above two take effect at the same time;
Related to viewing and managing command history Command
View the command history list: ~]# history
Command usage:
history -c: clear the command history;
history -d: OFFSET: delete the specified entry;
-a will Append the currently buffered history lines to the history file
-n        Read all unread lines from the history file 
-r       Read the history file and append the contents to the history list
           
Call the command in the command history list for re-execution:
!#: Execute the #th command in the history list again;
!!: Execute the previous command again;
!STRING : Execute again the latest command starting with the specified STRING in the command history list;
                    
Call the last parameter of the previous command:
Shortcut keys: ESC, . (press these two keys successively )
Alt .(Press these two keys at the same time)
!$: The parameters of the previous command given
Display the recent n conditional command history: history

##Bash basic features shortcut keys
Ctrl a: The cursor jumps to the beginning of the command line;
Ctrl e: The cursor jumps to the end of the command line;
Ctrl k: Delete from the cursor to the end Content;
Ctrl u: delete the content from the beginning of the line to the position of the cursor;


#Command line expansion of bash features:

Expand the given special information on the command line A mechanism for automatically replacing symbols with corresponding strings;
~: automatically replaced with the user's home directory;
~USERNAME: automatically replaced with the specified user's home directory;
{ }: can carry a comma-separated A path list that can be expanded into multiple independent paths;
Example: /tmp/{x,y,z} = /tmp/x /tmp/y /tmp/z
Example: /tmp/{ x/y, m/{m,n}} = /tmp/x/y /tmp/m/m /tmp/m/n
Example: /tmp/{x,y}/z = /tmp/ x/z /tmp/y/z


#Basic features of bash: command completion and path completion
Command completion:
After the shell program receives the user’s request to perform command completion (click Tab), the leftmost character The string will be used as a command to search;
The search mechanism:
1): Search internal
2): Search external commands: Go to each path specified by the $PATH variable, one by one from left to right Search for file names in each directory;
After the search is completed, if the given starting string can uniquely identify the file name of a command program file, it will be automatically completed as the command. If it cannot uniquely identify it, click tab again. A list can be given; if there is still no response, it means an error. No command can be identified by this leading string;
Path completion:
In the upper-level directory of the given starting path, match the directory under the corresponding path Start with a string to match each file under the upper-level target one by one: if it is a unique identifier, Tab completion; if it cannot be a unique identifier: tab, tab gives a list; error path: no response.

#bash features glob
glob: file name wildcard; quickly reference multiple files; overall file name matching detection
*: match any length of any character
? : Matches any single character
[ ]: Matches any single character in the specified set
[a-z]: Represents all letters, not case sensitive
[0-9]: Represents all numbers
[a-z0-9]: All letters plus digits
[[:upper:]]: All uppercase letters
[[:lower:]]: All lowercase letters
[[:digit:]] :All numbers
[[:alpha:]]:Represents all letters
[[:alunm:]]:Represents all letters plus numbers
[[:space:]]:Represents blank characters
[[:punct:]]: represents all punctuation marks
[^ ]: negates

The above is the detailed content of What are the basic features of bash. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template