当前位置:网站首页>13、 Command gadget
13、 Command gadget
2022-07-27 01:33:00 【JXin-xxx】
13、 ... and 、 Command gadget
cut: Column interceptor
Instructions :cut Command to cut bytes from each line of a file 、 Characters and fields and put these bytes 、 Write characters and fields to standard output . If you don't specify File Parameters ,cut Command will read standard input . Must specify -b、-c or -f One of the signs
Options :
| -b | Intercept by byte |
|---|---|
| -c | Intercept by character , Commonly used in Chinese |
| -d | Specify what to use as the delimiter to intercept , The default is tab |
| -f | Usually and -d Together |
[[email protected] ~]# cat /etc/passwd | cut -d':' -f 1
# Intercept /etc/passwd In the following : Split the first string
[[email protected] ~]# cat /etc/passwd | cut -d':' -f 3
# Intercept /etc/passwd In the following : Split the third string
[[email protected] ~]# cat /etc/passwd | cut -d':' -f1,3
# Intercept /etc/passwd In the following : Split the second 1 And 3 A string
[[email protected] ~]# cat /etc/passwd | cut -d':' -f1-3
# Intercept /etc/passwd In the following : Split the first to three strings
[[email protected] ~]# who | cut -b 3 # Intercept the third byte
[[email protected] ~]# who | cut -c 3 # Intercept the third character , It can be used to intercept Chinese
[[email protected] ~]# cat name | cut -b 2
[[email protected] ~]# cat name | cut -c 2
Be careful :cut Only good at dealing with text separated by a single character
sort
It is a tool to sort the contents of files in behavioral units , It can also be sorted according to different data types . For example, the sorting of data and characters is different
sort [ Options ] Parameters
Common options
| -t | Specify the separator , By default [Tab] Well Key or space separation |
|---|---|
| -k | Specify sorting area , Which interval is sorted |
| -n | Sort by number , The default is to sort in text |
| -u | Equate to uniq, Indicates that only one row of the same data is displayed , Be careful : If there is a space at the end of the line, de duplication will not succeed |
| -r | Reverse sorting , The default is ascending ,-r It's descending |
| -o | Transfer the sorted results to the specified file |
sort passwd.txt // Without any options, it is in ascending order of the first column by default , Letters are from a To z From above
sort -n -t: -k3 passwd.txt // Use colon as separator , Sort the third column by number size ( Ascending )
sort -nr -t: -k3 passwd.txt // Use colon as separator , Sort the third column by number size ( Descending )
sort -nr -t: -k3 passwd.txt -o passwd.bak // Output the input results not on the screen, but to passwd.bak file
sort -u passwd.txt // Remove duplicate lines from the file ( Repeated lines can be discontinuous )
uniq
It is mainly used to remove continuous repeated lines
Be careful : Is a continuous line , So usually with sort Combined with the use of sorting to make it a continuous row, and then perform the de duplication operation , Otherwise, he can't repeat the discontinuous lines
uniq [ Options ] Parameters
Common options
| -c | Count duplicate rows ; |
|---|---|
| -d | Show only duplicate lines ; |
| -u | Show only rows that appear once |
uniq -c // Count the number of repeated lines , He doesn't count as a repeating line
sort | uniq -c // combination sort Use
sort | uniq -d // combination sort Use , Filter out duplicate lines
sort | uniq -u // combination sort Use , Filter out non duplicate lines
example : View logged in users

example : Check the users who have logged in to the system

tr
It can replace one character with another , Or you can completely remove some characters , You can also use it to remove duplicate characters
tr [ Options ]… SET1 [SET2]
Replace... From standard input 、 Downsizing and / Or delete characters , And write the results to standard output .
Common options
| -d | Delete character |
|---|---|
| -s | Delete all duplicate characters , Keep only the first |
tr 'a-z' 'A-Z' # Replace lowercase content with uppercase
tr 'apple' 'APPLE' # Substitution is the substitution of one-to-one letters
tr 'a' ' ' # Enclose the replaced characters in single quotation marks , Include special characters , The character a Delete
tr 'a' '/' # take a Replace with /
tr 'ap' '/' # Replace multiple characters with one , take a and p Replace with /
tr 'apple' 'star' #a Replace with s,p Replace with a,le Replace with r
tr -d 'a' # Delete all a
tr "'" '/' # If you want to replace the single quotation mark, you need to enclose the single quotation mark with double quotation marks , Backslash escape doesn't work
tr -d 'apple' # Put everything that contains this 5 Delete all letters
tr -s 'p' # Yes p Character de duplication , Keep only the first
tr -s '\n' # When multiple carriage returns are encountered, only one carriage return is reserved , Equivalent to removing empty lines
1. Count the number of currently connected hosts
[[email protected] opt]# ss -nt | tr -s " " | cut -d " " -f5 | cut -d ":" -f1 | sort | uniq -c
1 20.0.0.1
1 Address
2. Count the connection status of the current host
[[email protected] opt]# ss -nta | grep -v '^State' | cut -d" " -f1 | sort | uniq -c
1 ESTAB
19 LISTEN
2. Count the connection status of the current host
[[email protected] opt]# ss -nta | grep -v '^State' | cut -d" " -f1 | sort | uniq -c
1 ESTAB
19 LISTEN
边栏推荐
猜你喜欢

Jenkins -- Basic -- 03 -- post installation setup wizard

Traversing binary trees in non recursive pre -, middle -, and post order

顺序表之OJ题

Esp8266 --- JSON data exchange format

Jenkins -- Foundation -- 02 -- Installation

MySQL关闭连接事务自动提交的问题

ESP8266 AP_ TCP_ Client

Unity常用的一些简易扩展方法

Unity ugui text text box adaptation

c语言实现三子棋游戏
随机推荐
大四老学长的自我批评记录
matlab基本介绍[1]
Play guest cloud brush machine 5.9
3. Boxing champion Ali
Unity screenshot widget
Problem feedback: the synchronization of mobile app failed: the external changes of the data warehouse were damaged. The iPad app also downloaded the warehouse as soon as it was opened, and then flash
Esp8266 --- JSON data exchange format
【Oracle】获取最近工作日及前N个工作日
Mqtt protocol ----- above
Basic DOS commands
MySQL关闭连接事务自动提交的问题
Come and help you understand the Internet of things in three minutes
Esp8266----- SNTP get network time
十三、命令小工具
十五、expect
MakeFile
Deep learning notes
Adding, deleting, checking and modifying dynamic sequence table with C language
Unity常用的一些简易扩展方法
iptables 防火墙(一)