Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic features of bash

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)05/31 Report--

What are the basic characteristics of bash? I believe many inexperienced people don't know what to do about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

# Command aliases for bash basic features

In the shell process, bash can set an alias for the command itself or the option of the command, and after setting it, you can directly enter the alias to invoke its function.

Set the command alias as: ~] # alias NAME=COMMAN.

The way to undo a command alias is: ~] # unalias NAME

The way to view command aliases that have been set in the current bash is: ~] # alias

Note 1: the command alias life cycle set in this way is only the current shell process. Log out of the current shell and log in again. To take effect automatically after shell starts, you need to set the configuration file related to the environment variables of bash.

Note 2: if the command alias and command name are the same, the function of the command defined by the alias is called directly. To directly call the command itself instead of an alias, you can use "~] #\ COMMAND.

# Command History of bash basic Features

Bash automatically saves commands that have been executed by users in its session in the shell process, and the record is stored in the memory space during the shell run. When the shell process ends, it persists the previously executed commands by storing them in a "history file". Every time the shell process starts, it reads the contents of the file into the memory space, and each user has its own dedicated history file.

Variables of history-related parameters

The number of historical commands retained by the buffer of the HISTSIZE:SHELL process

~] # echo $HISTSIZE to view 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 to view its size

~] # export HISTFILESIZE=# can set its size

HISTFILE: the command history file for the current user

~] # echo $HISTFILE to view the file name and address

HISTCONTROL: how the current user records the history of commands

~] # echo $HISTCONTROL to view the file name and address

~] # export HISTCONTROL= method name sets the way to record command history

There are three ways:

Ignoredups: ignore duplicate commands; repetition refers to consecutive and identical commands

Ignorespace: commands that start with a white space character are not recorded in history

Ignoreboth: both of the above take effect

Commands for viewing and managing command history

View command history list: ~] # history

Command usage:

History-c: clear command history

History-d:OFFSET: deletes the specified entry

-an append the history line of the current buffer 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

Invoke a command in the command history list for the purpose of reexecution:

! #: execute the # command in the history list again

!!: execute the last order again

! STRING: execute the most recent command in the command history list that starts with the specified STRING again

Invoke the last parameter of the previous command:

Shortcut key: ESC,. (press these two keys successively)

Alt +. (press both keys at the same time)

! $: the parameters of the previous command given

Displays the most recent history of n conditional commands: history #

# Shortcut keys for bash basic features

Ctrl+a: cursor jumps to the beginning of the command line

Ctrl+e: cursor jumps to the end of the command line

Ctrl+k: delete the content from where the cursor is to the end

Ctrl+u: deletes the content from the beginning of the line to the cursor

# expand the command line of bash's features:

A mechanism that automatically replaces a given special symbol on the command line with a corresponding string

~: automatically replace with the user's home directory

~ USERNAME: automatically replaced with the specified user's home directory

{}: can host a comma-separated list of paths that can be expanded into multiple independent paths

Example: / tmp/ {xonomery z} = / tmp/x / tmp/y / tmp/z

Example: / tmp/ {xgamy, m / {mdirection n}} = / tmp/x/y / tmp/m/m / tmp/m/n

Example: / tmp/ {xforme y} / z = / tmp/x/z / tmp/y/z

# basic features of bash: command completion and path completion

Command completion:

After the shell program receives a request from the user to complete the command (click Tab), the leftmost string will be looked up as a command

Its lookup mechanism:

1): find inside

2): find the external command: go to each path specified by the $PATH variable and search for the file names in each directory one by one from left to right

After the search is completed, if the given string that starts with a command can uniquely identify the file name of a certain command program file, it will automatically complete to the command and cannot be uniquely identified, and then click tab to give the list; if there is still no response, it will indicate an error, and no command can be identified by this leading string

Path completion:

Under the parent directory of the given starting path, match each file under the parent target one by one with the leading string under the corresponding path: if it is a unique identification, Tab completion; not unique identification: tab, tab gives a list; error path: no response.

# glob of bash's features

Glob: file name wildcard; quick reference to multiple files; overall file name matching detection

*: match any character of any length

? Match any single character

[]: matches any single character in the specified collection

[amurz]: indicates all letters, case-insensitive

[0-9]: represents all numbers

[a-z0-9]: all letters plus numbers

[[: upper:]]: all capital letters

[[: lower:]]: all lowercase letters

[[: digit:]]: all numbers

[[: alpha:]]: indicates all letters

[[: alunm:]]: indicates all letters plus numbers

[[: space:]]: represents a white space character

[[: punct:]]: indicates all punctuation marks

[^]: reverse

After reading the above, have you mastered the method of what the basic features of bash are? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report