1. sort - 文本排序
sort命令用于将文本文件的行排序。默认情况下,sort命令是按照字符串的字母顺序排序。
sort 的常用命令如下:
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 
 | sort example.txt
 
 
 sort -u example.txt
 
 
 sort -n example.txt
 
 
 sort -n -r example.txt
 
 
 sort file1 file2
 
 | 
2.uniq - 文本去重
uniq命令用于移除或发现文件中重复的条目。
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 
 | uniq example.txt
 
 
 uniq -c example.txt
 
 
 uniq -d example.txt
 
 
 uniq -D example.txt
 
 
 uniq -u example.txt
 
 
 uniq -w 3 example.txt
 
 
 uniq -s 3 example.txt
 
 
 uniq -f 1 example.txt
 
 | 
3.tr - 替换或删除字符
tr命令主要用于删除文件中控制字符或进行字符转换。使用tr时要转换两个字符串:字符串 1 用于查询,字符串 2 用于处理各种转换。tr刚执行时,字符串 1 中的字符被映射到字符串 2 中的字符,然后转换操作开始。
tr命令的语法如下所示:
| 1
 | tr [OPTION]... SET1 [SET2]
 | 
常用命令示例:
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 
 | tr '{}' '()' < textfile > newfile
 
 
 tr '{}' '\[]' < textfile > newfile
 
 
 tr 'a-z' 'A-Z' < textfile > newfile
 
 
 tr -cs '[:lower:][:upper:]' '[\n*]' < textfile > newfile
 
 
 tr -d '\0' < textfile > newfile
 
 
 tr -s '\n' < textfile > newfile
 
 
 tr -s '[:space:]' '[#*]'
 
 | 
4.grep - 查找字符串
grep命令用于搜索文本或指定的文件中与指定的字符串或模式相匹配的行。默认情况下,grep命令只显示匹配的行。
grep命令的语法如下所示:
| 12
 
 | grep [OPTION]... PATTERN [FILE]...grep [OPTION]... [-e PATTERN | -f FILE] [FILE]...
 
 | 
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 
 | grep blinkfox /etc/passwd
 
 
 grep -i blinkfox /etc/passwd
 
 
 grep -r blinkfox /etc/
 
 
 grep -w blinkfox /etc/
 
 
 grep -c blinkfox /etc/passwd
 
 
 grep -n blinkfox /etc/passwd
 
 
 grep -v blinkfox /etc/passwd
 
 
 grep --color blinkfox /etc/passwd
 
 | 
5.diff - 比较两个文件
diff命令用于比较两个文件,并找出它们之间的不同。diff命令的语法如下所示:
| 1
 | diff [OPTION]... from-file to-file
 | 
常用使用方式如下:
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 
 | diff nsswitch.conf nsswitch.conf.org
 
 
 diff -w nsswitch.conf nsswitch.conf.org
 
 
 diff -y nsswitch.conf nsswitch.conf.org
 
 使用 -c 选项,以上下对比的格式输出两个文件的比较结果
 diff -c nsswitch.conf nsswitch.conf.org
 
 | 
本文章由blinkfox原创,本站仅仅为学习转发