当前位置:网站首页>Do you know the shell foundation often asked in interviews?
Do you know the shell foundation often asked in interviews?
2022-07-18 15:32:00 【Love coriander】
One 、shell summary
1.Shell What is it?
shell It's a command line interpreter , He provides users with a way to linux The kernel sends requests to run the program's interface system level program , Users can use shell To start up 、 Hang up 、 Stop even writing programs
shell It is also a powerful programming language , Easy to write , Easy to debug , More flexibility .shell It's the script language that explains the execution , stay shell You can call linux System commands
2.Shell classification
1)Bourne Shell: from 1979 rise Unix Start using Bourne Shell,Bourne Shell The main file name is sh
2)C Shell:C Shell Mainly in the BSD Version of Unix The system uses , Its grammar and C The language is very similar , So called C Shell
Shell There are two main grammatical types of Bourne and C, The two grammars are not compatible with each other .Bourne The family mainly includes sh、ksh、Bash(linux The standard shell)、psh、zsh;C The family mainly includes :csh(unix The main use of shell)、tcsh
TIP: You can use commands :echo ¥SHELL To output what the current system uses shell
3)Bash:Bash And sh compatible , Currently in use linux Is the use of Bash As a basic user Shell
3.Linux Supported by Shell

Two 、 Script execution
1.echo The output command
echo [ Options ] [ Output content ]
Options :
-e: Support character conversion of backslash control


[[email protected] ~]# echo -e “\e[1;31m Hello \e[0m”
# Use red font to output Hello
#30m= black ,31m= Red ,32m= green ,33m= yellow ,34m= Blue ,35m= pink ,36m= Cyan ,37m= white
In the above line of example code \e Representative color ,[1 On behalf of winking ,31m Means I want to use red ,\e[0m Represents off color
2. The first script
1) Use command “vi hello.sh” Create a script
2) Enter... In the text :”#!bin/bash”( Make a statement )
3) Text input :echo –e “Hello World!”, Then save to exit
3. Script execution
1) Grant execution permission , Direct operation
chmod 755 hello.sh
./hello.ssh
2) adopt Bash Call the execution script
bash hello.sh
3、 ... and 、bash Basic functions of
1. Command aliases and shortcuts
alias
# View all command aliases in the system
alias Alias =’ The original order ’
# Set command alias ( It should be noted that adding aliases only with the command line is only temporary , amount to windows Temporary environment variables in )

1) The alias is permanent
vi ~/.bashrc
# Write environment variable configuration file ( It should be noted that it will take effect only after the device is restarted after writing , If you need to take effect directly, you need to add another order source .bashrc It's equivalent to updating, so it can take effect directly )
2) To delete an alias
unalias Alias
# To delete an alias ( Just delete the temporary alias )
3) Order of order
The first sequence executes a command executed with an absolute path or a relative path
Second order execution alias
Third order execution bash The internal order of
The fourth order is executed according to ¥PATH The first command found in the directory lookup order defined by the environment variable
4) Common shortcut key

2. History commands
1) History commands
history [ Options ] [ The history command saves the file ]
Options :
-c: Clear history command
-w: Writes the history command from the cache to the history command to save the file ”~/.bash_history”
history See all the historical orders ,.bash_history The history command in is written automatically when the system exits .
It should be noted that historical commands will be saved by default 1000 strip , Can be configured in the environment variables file /etc/profile Modify in process

2) Call of history command
Use the up and down arrows to call up the previous historical commands
Use ”!n” Repeat step n Historical orders
Use ”!!” Repeat the last command
Use ”! character string ” Repeat the last command that starts with the string
3) Command and file completion
stay bash in , Command and file completion is a very convenient and commonly used function , We just enter a command or file , Press down Tab Key will automatically complete
3. Output redirection
1) Standard input and output

Standard output redirection saves the results of the command in a file ( As long as the result of the command has output, it will be saved )

Error output redirection ( Note that there is no space on either side of the symbol )


ls &>/dev/null Execute commands only , Do not save or display the running results ,/dev/null It can be used as a garbage collector
command >> file 2>&1
Save the correct output and the wrong output in the same file by appending 1

command &>> file
Save the correct output and the wrong output in the same file by appending 2

command >> file 1 2 >> file 2
Append the correct output to the file 1 in , Append the wrong to the file 2 in

3) Input redirection
wc [ Options ] [ file name ]
ctrl+d sign out

Use wc Count file lines 、 Number of words 、 And the number of bytes , You can also use the one in the middle < Symbols can also be counted

4. Pipe,
1) Multiple commands are executed sequentially

Multiple commands are executed in sequence

Logic and

Logic or

TIP: It can be done by analogy :ls && echo yes || echo no This way to judge whether the command is wrong
2) Pipe,
command 1 | command 2
# command 1 The correct output for the command 2 Operation object of
for example :
ls –l /etc | more To view the command execution results in separate screens
netstat –an | grep ESTABLISHED To monitor my server usage
netstat –an | grep ESTABLISHED | wc –l To see how many people are using our server
5. wildcard
1) wildcard

for example :
ls test* List test All the documents at the beginning
Mainly match the file name or directory
2)Bash Other special symbols in


Now I invite you to join our software testing learning exchange group :【746506216】, remarks “ The group of ”, We can discuss communication software testing together , Learn software testing together 、 Interview and other aspects of software testing , There will also be free live classes , Gain more testing skills , Let's advance together Python automated testing / Test Development , On the road to high pay .
Friends who like software testing , If my blog helps you 、 If you like my blog content , please “ give the thumbs-up ” “ Comment on ” “ Collection ” One Key triple connection !
边栏推荐
- 【无标题】
- What is a recommendation system?
- (cvpr-2022) Lagrangian motion analysis and perspective embedding for improved gait recognition
- 2022 pole technology communication - anmou technology opens a new chapter of commercialization
- Codeforces Round #806 (Div. 4)
- JS Object.keys()
- Mipi c-phy popular science
- page-break-before\page-break-inside\page-break-after用法
- C语言《通讯录》详解
- 选取某个分类占比最大的值,作为该分类的唯一值
猜你喜欢

RS485接口OSI模型的应用层

选取某个分类占比最大的值,作为该分类的唯一值

The bottom logic of learning essence

C # use marshall Sizeof calculation structure size returned error

Enable sandbox function and use in win10

Distributed notes (01) - theory and principle of distributed cap

MIPI CSI、DSI、UFS、C-PHY、D-PHY、M-PHY概念理解

page-break-before\page-break-inside\page-break-after用法

亚马逊卖家该如何做好防关联?不砍单!(测评自养号详解)

无线通信中LoRa技术特点
随机推荐
mysql与idea建立连接出错
MIPI CSI、DSI、UFS、C-PHY、D-PHY、M-PHY概念理解
Symbolic naming analysis in reinforcement learning
Onnx model tensor shapes information and flops statistical tools
AGCO won the 2022 red dot award: design concept award
全链路压测 :测试要做的准备工作
Go environment installation
cv2.setMouseCallback()显示鼠标点击图片的像素值和位置
Soft exam (intermediate software designer) exam information
【通信】【1】幅度调制,频率调制,双边带与单边带,IQ与PSK与QAM——采样一定要满足奈奎斯特定理吗
Get to know your NFT again
免费SSL证书申请及部署实践
GooglePhoto设置壁纸----壁纸裁剪界面配置
[daily training] 515 Find the maximum value in each tree row
物联网无线传输技术参数对比表
Codeforces Round #806 (Div. 4)
C1083: unable to open include file: 'corecrt.h'
【成像】【9】太赫兹光学——光学系统
架构基础篇
通过制定愿景克服数字化转型挑战