当前位置:网站首页>Chapter 4 - understanding standard equipment documents, filters and pipelines
Chapter 4 - understanding standard equipment documents, filters and pipelines
2022-04-23 04:27:00 【Inter personal liabilities^】
Understand the standard equipment documents 、 Filters and piping
Understand the standard equipment documents
Linux Treat all input and output devices as special files
Standard input file
When you need to execute the entered command ,Shell
Translate commands and use the keyboard as the default input source . The keyboard is called a standard input file .
cat
When the command is followed by a file name , All lines will be displayed , If there is no filename ,cat
The command gets its input from the standard input file
cat
Command waiting for keyboard input , Enter characters from the keyboard and press Eenter Key time , The characters will be displayed on the screen
Input :
cat This is a test to depict
Output :
This is a test to depict
Enter as many lines as you want , If you want to prompt for the end , Need to press Ctrl + d
key
stay Linux in , Not all commands come from standard input files ,cd
Commands do not use standard input files
stay Linux in , For all open files ( Including standard documents ) Assign a number called a file descriptor . File descriptor 0 Assigned to the standard input file
Standard output file
Shell
Use the display as the default output device for any command it executes . The display is called a standard output file .
issue ls
On command ,Shell
Execute the command and output it ( List of directories ) Occurs to the standard output file
Not all commands generate output ,mkdir
The command does not use the standard output file
File descriptor 1 Represents the standard output file
Standard error file
for example :cat
The command is followed by a nonexistent file name 、cp filel dirl
, Yes file
or dirl
No authority
File descriptor 2 Indicates the standard error file
Redirect input or output
- Input redirection
- Output redirection
- Error redirection
Input redirection
cat < test1
<
From a file test1
Redirect input .
cat
Will file test1
Each line of is regarded as input and displayed on the display
The above command can be written through the file descriptor
cat 0< test1
0<
Indicates input redirection
Output redirection
cat test1 > out_test
>
Indicates redirecting output to a file out_test
, Also is to cat
The output of the command is written to the disk file out_test
If out_test
file does not exist , First create an empty file , Write again
If out_test
File exists , Then delete the previous content , Write again
cat test1 >> out_test
Attach output to file out_test
Use file descriptors to write
cat test1 1> out_test
cat test1 1>> out_test
Error redirection
cat test_2 2> error-mesg
hypothesis test_2
Not in current directory , therefore , When the user tries to execute this command ,Linux An error message will be generated , Then write the error message to the file error-mesg
Use filters
A filter is a program , Get input from standard input file , Handle ( Or filtration ) It and sends the output to the standard output file
grep filter
grep The filter searches by regular expression
File name is optional , If there is no filename ,grep
Wait for standard input , After entering a line ,grep
Search for regular expressions in rows , If this particular expression is included, this line is displayed , On the contrary, it does not show .
Key Ctrl + d
End of input
Specify regular expressions
character | usage | Example |
---|---|---|
[] | Match any one of a set of characters | grep “New[abc]” |
[] Inside plus - | Matches any one of the characters in a range | grep “New[a-c]” |
^ | Subsequent styles must appear at the beginning of each line | grep “^New[abc]” |
[] Inside plus ^ | The style must not contain any characters in the specified set | grep “New[ ^ a-c]” |
$ | The previous style must appear at the end of each line | grep “New[abc]$” |
.( spot ) | Matches any character | grep “New.[abc]” |
( The backslash ) | Or the special meaning of the characters slightly followed | grep “New.[abc]” |
grep Filter options
grep Filters also have some options , Can be used to change the output of a command
- -n: Print each line that matches the style and its line number . The line number is printed at the beginning of the line .
- -c: Print the number of lines that match the style
- -v: Print all lines that do not match the style specified by the regular expression
wc filter
wc Filters are used to calculate the number of lines in disk files or standard input files 、 Number of words and characters
Provide file name
wc test
Output :1 5 22 test
Said file test
There is 1 That's ok 、5 A word and 22 Characters
Do not provide file name
wc wc is a filter
Press Ctrl + d
Output :1 4 15
wc Filter options
Options | describe |
---|---|
-l | Display row number |
-w | Show the number of words |
-c | Show the number of characters |
cut filter
When required from a specific command (ls or who) Extract a specific column from the output of , have access to cut filter
Options | describe |
---|---|
-f | Displays the specified column |
-c | Display the specified characters |
-d | Specify the column delimiter .Tab Is the default column delimiter |
tr filter
- tr Filters can be used to translate one set of characters into another .
- It can also be used to delete duplicate characters .
Remove duplicate characters ( Compress )
-s
Used to compress repeated characters into one character
Convert case
tr "[a-z]" "[A-Z]"
Convert lowercase characters to uppercase characters
sort filter
sort The filter arranges each line in the standard input in ascending order .
Need to enter sort command , Then enter the data to sort , Then you need to press Ctrl + d
Key sort data
sort Filter options
- -r Options : In reverse order ( Descending ) Sort input
- -f Options :sort The filter is in the form of characters ASCII The order of code values is numbers 、 Input sort consisting of letters and other characters
- -n Options : In a ASCII Sequence numbers
- < filename >: Sort the contents of the specified file , Displays the rows of the file in sorted order
- +pos1 -pos2 Options : Sort files in the order of specific columns
- -t Options : Sort files based on specific column separators
- -o Options : take sort The output of the filter is saved in a disk file , Not on the standard output
Use pipes
Linux With combined filters and other commands ( for example ls
) The function of , In this way, the standard output of a filter or command can be sent as standard input to another filter or command
give an example
ls > tempfile
more tempfile
Besides , Store the list of directories in a file with the first command tempfile in , This file is then more Command display content
adopt Linux Pipeline function , These two steps can be combined and executed as one command , No need to create temporary files
ls | more
A vertical bar ( | ) It's a pipe character , instructions Shell take " | " The output of the previous command is sent as input to the subsequent command
Another advantage of pipelining is that you don't have to rewrite utilities to perform complex tasks
tee command
tee The command reads standard input and writes it to standard output and files .
If the file to write data does not exist , The file will be created .
If the file already exists , Just rewrite the contents of the file .
-a
Option allows you to attach new content to an existing file
版权声明
本文为[Inter personal liabilities^]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230426392769.html
边栏推荐
- Shopping mall for transportation tools based on PHP
- 【时序】基于 TCN 的用于序列建模的通用卷积和循环网络的经验评估
- 【Pytorch基础】torch.split()用法
- Matlab minimalist configuration of vscode configuration
- C语言: 指针的进阶
- Single chip microcomputer serial port data processing (1) -- serial port interrupt sending data
- 电钻、电锤、电镐的区别
- IEEE Transactions on Systems, Man, and Cybernetics: Systems(TSMC)投稿须知
- Interaction of diet gut microbiota on cardiovascular disease
- Microbial neuroimmune axis -- the hope of prevention and treatment of cardiovascular diseases
猜你喜欢
[AI vision · quick review of robot papers today, issue 30] Thu, 14 APR 2022
【论文阅读】【3d目标检测】Voxel Transformer for 3D Object Detection
Why recommend you to study embedded
STM32 upper μ C / shell transplantation and Application
使用大华设备开发行AI人流量统计出现时间不正确的原因分析
Common string processing functions in C language
[AI vision · quick review of NLP natural language processing papers today, No. 32] wed, 20 APR 2022
一个函数秒杀2Sum 3Sum 4Sum问题
LabVIEW 小端序和大端序区别
用D435i录制自己的数据集运行ORBslam2并构建稠密点云
随机推荐
递归调用--排列的穷举
Matlab reads multiple fig graphs and then combines them into one graph (in the form of sub graph)
【ICCV 2019】MAP-VAE:Multi-Angle Point Cloud-VAE: Unsupervised Feature Learning for 3D Point Clouds..
Go 语言中的 logger 和 zap 日志库
io.Platform.packageRoot; // ignore: deprecated_member_use
Hard core chip removal
Understand the gut organ axis, good gut and good health
QT program integration easyplayer RTSP streaming media player screen flicker what is the reason?
C语言常用字符串处理函数
What is software acceptance testing? What are the benefits of acceptance testing conducted by third-party software testing institutions?
Operating skills of spot gold_ Wave estimation curve
Why recommend you to study embedded
单极性非归零NRZ码、双极性非归零NRZ码、2ASK、2FSK、2PSK、2DPSK及MATLAB仿真
国外LEAD,联盟经理常见问答
HMS Core Discovery第14期回顾长文|纵享丝滑剪辑,释放视频创作力
那些年我面试过的Android开发岗总结(附面试题+答案解析)
LabVIEW 小端序和大端序区别
一个函数秒杀2Sum 3Sum 4Sum问题
Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
Chlamydia infection -- causes, symptoms, treatment and Prevention