当前位置:网站首页>Wildcards and special symbols for shell scripts
Wildcards and special symbols for shell scripts
2022-04-23 06:48:00 【tilblackout】
wildcard :
Symbol |
significance |
* |
0 To infinite arbitrary characters |
? |
An arbitrary character |
[] |
Such as [abcd] Express a,b,c,d Any one of |
[-] |
All characters in encoding order , Such as [0-9] Express 0 To 9 Between the digital |
[^] |
Reverse selection , Such as [^abc] Express non a,b,c Other characters of |
Special symbols :
Symbol |
Content |
| |
pipeline : Define the split two pipeline commands |
& |
Work control : Change the instruction to run in the background |
>,>> |
Data flow redirection : Output guide , Namely “ replace ” And “ Add up ” |
<,<< |
Data flow redirection : Input guide |
(1) Data flow redirection : Data that should appear on the screen after an instruction is executed (stdout/stderr) Transfer to other places
- The standard input (0): Use < or <<
- standard output (1): Use > or >>
- The standard error (2): Use 2> or 2>>( If you don't write numbers, the default is 1)
Example :
example 1:
ll / > ~/rootfile # Output the contents of the root directory to the file
>: If the file does not exist, create , Existence covers
>>: If it exists, it adds
example 2:
find /home -name .bashrc>list_right 2>list_error # take stdout And stderr Save to different files
example 3: Write both correct and wrong information to list in
find /home -name .bashrc>list 2>list # error
find /home -name .bashrc>list 2>&1 # correct
find /home -name .bashrc &>list # correct
example 4:
cat > catfile # User input characters , Then save to catfile in
cat > catfile < ~/.bashrc # The characters entered are composed of bashrc Provide storage in catfile in ( Copy )
example 5:
cat > catfile << "eof" #<< The input character representing the end , Input eof Then end the input
Be careful :
- /dev/null Black hole device , You can output unwanted information to /dev/null in
find /home -name .bashrc 2>/dev/null # Discard the wrong data , The correct data is displayed on the screen
(2) Pipe symbol “|” Use :
ls -al /etc|less #ls Of stdout As less Ordered stdin
- stay "|" The following designation must be a pipeline command ( Acceptable stdin), Such as less、more、head、tail
- Route commands only process stdout, about stderr Will ignore
Examples of common pipeline commands :
1.cut
cut -d ' Separator character ' -f fields #-f To take out the paragraphs , Result subscript from 1 Start
cut -c Character range # Take the fixed character interval as the unit of characters
example :
echo $PATH | cut -d ':' -f 5 # Take out No 5 individual
echo $PATH | cut -d ':' -f 3,5 # Take out No 3 With the first 5 individual
export | cut -c 12- # Take out No 12 String after characters
export | cut -c 12-20 # Take out 12-20 String
2.grep
Options :--color=auto You can highlight keywords in the results
example :
last | grep 'root' # Take out yes root The line of
last | grep -v 'root' # Take out no root The line of
last | grep 'root' |cut -d ' ' -f1 # Take out yes root The first column of the row
3.sort: Sort
-t: Separator -k: Sort by the interval separating the results -r: Reverse sorting -f: Ignore case -b: Ignore the first space -n In numerical order
example : Sort the account numbers
cat /etc/passwd | sort
cat /etc/passwd | sort -t ':' -k 3 # Sort in the third column
cat /etc/passwd | sort -t ':' -k 3 -n # The above sort is sorted by string ,1 It will appear in 11 Back ,-n Point out sorting by number
4.uniq: Remove duplication
example :
last | cut -d ' ' -f1 | sort | uniq [-c] # Remove duplication ,-c For count
5.wc: Statistics
example :
cat /etc/man.config | wc # The three numbers output represent : That's ok 、 Number of words 、 Number of characters
6.tee: As input to the pipeline , Also output to the screen
last | tee last.list # Output to screen and last.list
7.tr: Delete or replace text
-d: Delete the following string -s: Replace duplicate characters
example :
last | tr '[a-z]' '[A-Z]'
cat /etc/passwd | tr -d ':' # Remove the colon from the result
minus sign - Use of
In the pipeline command , Will use the previous instruction stdout As this time stdin, When some instructions need to be processed with file names , The stdin And stdout You can use the minus sign “-” Instead of . example :
tar -cvf - /home | tar -xvf -
- use tar pack /home, Fill in the file name and location “-”, The packed data is transferred to stdout, Then the back tar Of “-” Is the of the previous instruction stdout.
版权声明
本文为[tilblackout]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230549282609.html
边栏推荐
猜你喜欢
HDU-Tunnel Warfare
VHDL 有限状态机(FSM) 代码示例
[UDS unified diagnostic service] II. Network layer protocol (2) - data transmission rules (single frame and multi frame)
Informatics one book pass - small ball
基于VGG对五种类别图片的迁移学习
说说ts的心里话
[UDS unified diagnostic service] IV. typical diagnostic service (5) - function / component test function unit (routine function unit 0x31)
逻辑回归原理及代码实现
深蓝学院激光slam理论与实践 -第二章(里程计标定)作业
浮点数双精度,单精度以及半精度知识总结
随机推荐
获取当前一周的时间范围
浮点数双精度,单精度以及半精度知识总结
POJ-The Unique MST
查漏补缺(九)---程序篇
2022LDU寒假训练-程序补丁
SSH 公钥 私钥的理解
Understanding of SSH public key and private key
Makefile foundation, common functions and general makefile
[UDS unified diagnostic service] II. Network layer protocol (1) - overview and functions of network layer
[UDS unified diagnosis service] IV. typical diagnosis service (1) - diagnosis and communication management function unit
Shell脚本 &&和||的使用
Node的数据库编程
[UDS] unified diagnostic service (UDS)
深蓝学院激光slam 理论与实践 第三章激光雷达去畸变 作业习题
ROS包nmea_navsat_driver读取GPS、北斗定位信息笔记
el-table添加序号
查漏补缺(四)
谈谈v-if显示隐藏问题
js根据名字将数组对象中名字相同的项组成一个相同的数组
ARM常用汇编指令