当前位置:网站首页>rhcsa 第四天
rhcsa 第四天
2022-08-01 06:41:00 【喳喳叽】
目录
a. cat查看/etc/passwd文件内容,且输出时带行号
b.使用more/less查看/etc/passwd内容,且每页显示10行
c.使用head/tail分别查看文件前5行内容和后5行内容
d.使用grep查看/etc/passwd中和root相关的内容
一.文件内容浏览
命令


说明:以上所有命令均可以结合管道符使用
a. cat查看/etc/passwd文件内容,且输出时带行号

b.使用more/less查看/etc/passwd内容,且每页显示10行
[[email protected] ~]# more -10 /etc/passwd
[[email protected] ~]# less -10 /etc/passwd

c.使用head/tail分别查看文件前5行内容和后5行内容
[[email protected] ~]# head -5 /etc/passwd
[[email protected] ~]# tail -5 /etc/passwd

d.使用grep查看/etc/passwd中和root相关的内容
[[email protected] ~]# grep root /etc/passwd
二.cut命令使用:
cut命令用于按列提取文本内容,语法为: cut [选项] 文件名称
系统文件在保存用户数据信息时,每一项值之间是采用冒号来间隔的,先查看一下:
cut命令的使用

给定文件cut_data.txt且内容为:
| No | Name | Score | |
| 1 | zhang | 20 | |
| 2 | li | 80 | |
| 3 | wang | 90 | |
| 4 | sum | 60 |
使用默认定界符切割文件内容,且输出切割后的第一个字段
[[email protected] ~]# touch cut_data.txt
[[email protected] ~]# vim cut_data.txt
rootarhcsa ~]# cat cut_data.txt
No Name Score
1 zhang 20
2 li 80
3 wang 90
4 sun 60
[[email protected] ~]# cut -d" " -f1 cut_data.txt
No
1
2
3
4切割文件内容,且输出切割后的第一个字段和第三个字段
[[email protected] ~]# cut -d" " -f1,3 cut_data.txt
No Score
1 20
2 80
3 90
4 60按字节切割:输出切割的第一个字节到第10个字节的内容
[[email protected] ~]# cut -b 1-10 cut_data.txt
No Name Sc
1 zhang 20
2 li 80
3 wang 90
4 sun 60按字符切割:输出切割后的第一个字符和第5个字符的内容
[[email protected] ~]# cut -c 1,5 cut_data.txt
Na
la
2
3n
4n 按指定分界符去切割:内容如下, 输出第一个字段和第三个字段内容
No|Name|Score
1|zhang|20
2|li|80
3|wang|90
4|sun|60
[[email protected] ~]# vim cut_data.txt
[[email protected] ~]# cat cut_data.txt
No|Name|Score
1|zhang|20
2|li|80
3|wang|90
4|sun|60
[[email protected] ~]# cut -d"|" -f1,3 cut_data.txt
No|Score
1|20
2|80
3|90
4|60
三.uniq命令使用:
新建文件uniq_data.txt,文件内容为
Welcome to Linux
Windows
Windows
Mac
Mac
Linux
使用uniq命令输出去重后的结果
[[email protected] ~]# touch uniq_data.txt
[[email protected] ~]# vim uniq_data.txt
[[email protected] ~]# cat uniq_data.txt
Welcome to Linux
Windows
Windows
Mac
Mac
Linux
[[email protected] ~]# uniq uniq_data.txt
Welcome to Linux
Windows
Mac
Linux使用uniqmingl只输出重复的行
[[email protected] ~]# uniq -d uniq_data.txt
Windows
Mac使用uniq命令输出不重复的行
[[email protected] ~]# uniq -u uniq_data.txt
Welcome to Linux
Linux使用uniq命令统计重复次数
[[email protected] ~]# uniq -c uniq_data.txt
1 Welcome to Linux
2 Windows
2 Mac
1 Linux
四.sort命令:
sort命令用于对文本内容进行排序显示,语法为: sort [选项] 文件名称
sort命令使用
给定文件 num.txt, args.txt
文件内容:num.txt
1
3
5
2
4
文件内容:args.txt
test
args1
args2
args4
args4
args3
对num.txt进行排序,且将结果输出到sorted_num.txt中
[[email protected] ~]# touch num.txt
[[email protected] ~]# vim num.txt
[[email protected] ~]# cat num.txt
1
3
5
2
4
[[email protected] ~]# sort num.txt >> sorted num.txt
[[email protected] ~]# more sortes num.txt
more: stat of sortes num.txt failed: No such file or directo
1
2
3
4
5对args.txt进行排序,且将结果输出到sorted_args.txt中
[[email protected] ~]# touch args.txt
[[email protected] ~]# vim args.txt
[[email protected] ~]# cat args.txt test
argsl
args2
args4
args4
args3
[[email protected] ~]# sort args.txt >> sorted_args.txt
[[email protected] ~]# more sorted_args.txt
args1
args2
args3
args4
args4
test对num.txt和args.txt进行排序,且将结果输出到sorted_merge.txt中
[[email protected] ~]# sort -n args.txt num.txt>>sorted_merge.txt
[[email protected] ~]# more sorted _merge.txt
args1
args2
args3
args4
args4
test
1
2
3
4
5对args.txt排序后去重输出
[[email protected] ~]# sort -u args.txt
args1
args2
args3
args4
args4
test合并sorted_args.txt和sorted_num.txt且输出
[[email protected] ~]# cat sorted_args.txt >> sorted num.txt
[[email protected] ~]# more sorted_num.txt
1
2
3
4
args1
args2
args3
args4
args4
test给定文件info_txt:按第二列作为key进行排序
| No | Name | Score | |
| 1 | zhang | 20 | |
| 2 | li | 80 | |
| 3 | wang | 90 | |
| 4 | sum | 60 |
[[email protected] ~]# touch info.txt
[[email protected] ~]# vim info.txt
[[email protected] ~]# sort -t" " -k2 info.txt
2 li 80
No Name Score
4 sun 60
3 wang 90
1 zhang 20
五.替换文件中的字符显示tr
tr 指令从标准输入读取数据,经过替换或者删除后,将结果输出到标准输出。
将26个小写字母的后13个字母替换成大写字母
[[email protected] ~]# echo :"abcdefghijkmlnopqrstuvwxyz"| tr n-z N-Z
:abcdefghijkmlNOPQRSTUVWXYZ将hello 123 world 456中的数字替换成空字符
[[email protected] ~]# echo "hello 1223 world 456" | tr 1-6 “ ”
hello world将hello 123 world 456中字母和空格替换掉,只保留数字
[[email protected] ~]# echo "hello 123 world 456" | tr -c 1-6 " "
123 456边栏推荐
- uva12326
- 解决浏览器滚动条导致的页面闪烁问题
- How JS works
- Induction jian hai JustFE 2022/07/29 team, I learned the efficient development summary (years)
- ORACLE 实现另外一个用户修改包(package)
- LeetCode每日一题(309. Best Time to Buy and Sell Stock with Cooldown)
- Create, modify and delete tables
- Practical training Navicat Chinese and English mode switching
- ORACLE modify another user package (package)
- MATLAB程序设计与应用 2.5 MATLAB运算
猜你喜欢
随机推荐
对于升级go1.18的goland问题
Xiaobai's 0 Basic Tutorial SQL: An Overview of Relational Databases 02
Windows taskbar icon abnormal solution
Offer刷题——1
Information system project managers must recite the work of the core test site (56) Configuration Control Board (CCB)
Dell PowerEdge Server R450 RAID Configuration Steps
ORACLE 实现另外一个用户修改包(package)
uva12326
Selenium: Dropdown Box Actions
leetcode125 验证回文串
Hunan institute of technology in 2022 ACM training sixth week antithesis
数据机构----线性表之单向链表
「游戏引擎 浅入浅出」4.1 Unity Shader和OpenGL Shader
说说js中使用for in遍历数组存在的bug
表的创建、修改与删除
Matlab simulink particle swarm optimization fuzzy pid control motor pump
LeetCode 0150. Reverse Polish Expression Evaluation
Induction jian hai JustFE 2022/07/29 team, I learned the efficient development summary (years)
牛客刷SQL---2
Explosive 30,000 words, the hardest core丨Mysql knowledge system, complete collection of commands [recommended collection]












