This is the 30th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021
What is the Bash shell
Bash shell is equivalent to an application program. We input commands to Bash shell, which is translated into binary and transmitted to the Linux system. The system calls the kernel, which operates the hard disk and performs operations.
The Bash shell allows us to interact with computers, translate human execution into binary instructions that computers can understand, and manipulate hard disks.
What the bash shell does
Add, delete, change and check all kinds of management
File management
Add, delete, change and check files
# create file
touch xx.txt
# modify fileVim fileechoXXX > file# view file
cat less head grep awk
Copy the code
Rights management
User management
Disk management
Software management
Network management
.
The bash shell uses two ways
- The command line
- Shell scripting language
The shell prompt
[root@zhuang ~]# Zhuang: The first part of the dot delimiter in the default real host name ~ : the current directory. By default, only the last folder in the current directory is displayed. ~ indicates the home directory of user root# : indicates the command prompt for the superuser$: indicates the command prompt of a common userCopy the code
Modify the shell prompt
In bash shell commands, $represents a variable and needs to be distinguished from the prompt
View the default command prompt
echo $PS1
[\u@\h \W]\$
# change command prompt:
vim /root/.bashrc
# Add content\u: Current user \h: Current host name, if there is any, display the first part with dot delimiter \H: full host name \W: last directory of the current path \W: full directory of the current path, absolute path \d: actual current date \t:24h display time minute \T:12h display time minute \A: The display time is 24 hours in HH: MM \v:bash version information \#: Displays the number of commands currently issued\$: Command prompt for the current user, if super userNormal users will display $
Copy the code
Bash shell basic syntax
Basic syntax, command option parameters, options and parameters can have multiple
command option arguments
# for
ls
ls -a
ls -l -a /usr/local/
ls -la /usr/local/ /tmp/
Copy the code
Basic bash shell features
Command completion -tab
You can complete the command
You can complete a path
If you want to complete the command, the installation package is not required
yum install -y bash-completion
Copy the code
Command options
Options are available in long format and long format
ls -a Short format is used by default
ls --all
Copy the code
Command shortcut keys
CTRL + A: Jumps the cursor to the beginning of the current command. CTRL + E: jumps the cursor to the end of the current command. CTRL + W: Deletes the content before the cursor by following the space. CTRL + C: terminates the current command CTRL + D: Exit the current bash, exit only one, similar to exiting the current logged-in user, CTRL + Z: Run the process in the background CTRL + K: Delete everything from the cursor to the end of the line CTRL + U: Delete everything from the cursor to the beginning of the line CTRL + left and right keys: Quickly move the cursor Esc +.: Quickly retrieves the content after the last space of the previous command! + letters: find the latest command with a specified letter in history. : Execute the last command! + number: Executes a history command with a specified number in history# not commonly usedCTRL + S: Lock the screen CTRL + Q: All the contents entered during the lock are output after the unlockCopy the code
History – History command
The history command is mainly used for auditing
Delete history command
history -c
# delete a historical record
histoty -d 4 # Delete the fourth history
Save history to /root/.bash_history
history -w
# Change the display of history
vim /etc/profile
# shift + g to the last line
USER_IP=`who -u am i 2>/dev/null | awk '{print $NF}' | sed -e 's/[()]//g'`
if [ "$USER_IP" = "" ]
then
USER_IP=`hostname`
fi
export HISTTIMEFORMAT="% % F | T | user IP:$USER_IP| operation user: ` whoami ` | operation command:"
shopt -s histappend
export PROMPT_COMMAND="history -a"
# take effect
source /etc/profile
Copy the code
Command alias alias
Simplify complex commands, but do not use aliases such as /bin/cp if you use absolute paths to commands
alias wk='vim /etc/systemconfig/network-scripts/ifcfg-etho'
# usage, temporary Settings
alias # check the current system alias
alias grep="grep --color=auto" Create an alias. If the name already exists, create an alias
unalias wk # delete alias
It takes effect permanently under user root
vim /root/.bashrc
alias wk='vim /etc/systemconfig/network-scripts/ifcfg-etho'
source /root/.bashrc
Copy the code
Command to Obtain help
The command -helpOr the man commandCopy the code
conclusion
The article was first published in the wechat public account Program Yuan Xiaozhuang, at the same time in nuggets.
The code word is not easy, reprint please explain the source, pass by the little friends of the lovely little finger point like and then go (╹▽╹)