網站首頁 編程語言 正文
目錄
- cat命令
- 1 cat在查看文件內容時同時輸出行號應該怎么做?
- 2 more 命令
- 3 grep命令
- 4 head , tail 命令
- 1 head 查看內容
- 2 tail 查看內容
- cut命令
- 1 要求剪切后輸出第一個字段
- 2 輸出第一字段和第三字段內容
- uniq命令
- 1 使用uniq命令輸出去重后的結果
- 2 使用uniq命令只輸出重復的行
- 3 使用uniq命令統計重復的次數
- sort命令
- 1 對num.txt排序,并且將結果輸出到sorted_num.txt中
- 2 對args.txt排序,并且將結果輸出到sorted_args.txt中
- 3 對args.txt和num.txt排序,并將結果輸出到sorted_merge.txt中
- 4 對args.txt排序后去重輸出合并sorted_args.txt和sorted_num.txt且輸出給定文件info.txt按第二列作為key進行排序
- tr命令
- 1 將后14個英文字母變成大寫
- 2 將文件中數字變為空字符
- 結束
cat命令
1 cat在查看文件內容時同時輸出行號應該怎么做?
如下:查看/etc/passwd/下的內容并且輸出行號
注意:/etc/passwd/ 這個文件下不是關于密碼的配置文件,而是關乎于用戶的配置文件。
命令:
[root@localhost Desktop]# cat -n /etc/passwd
2 more 命令
例:還是查看/etc/passwd目錄下的內容:
more命令:
[root@localhost Desktop]# more -p10 /etc/passwd
3 grep命令
例: 查看/etc/passwd 中和root相關的內容:
命令:
[root@localhost Desktop]# grep -G "root" /etc/passwd
4 head , tail 命令
1 head 查看內容
例:查看 /etc/passwd 內容的前5行內容:
命令:
[root@localhost Desktop]# head -n 5 /etc/passwd
默認是輸出10行
2 tail 查看內容
例:查看 /etc/passwd 內容的前5行內容:
命令:
[root@localhost Desktop]# tail -n 5 /etc/passwd
默認輸出也是10行。
cut命令
首先創建一個文件:cut_data.txt ,且內容為:
No Name Score
1 zhang 20
2 li 80
2 wang 90
4 sun 60
1 要求剪切后輸出第一個字段
命令:
[root@localhost Desktop]# cut -b 1-2 cut_data
結果如下:
按字節切割,輸出切割后的第一個字節到第10個字節的內容:
[root@localhost Desktop]# cut -b 1-10 cut_data
按字符切割,輸出切割后的第一個字符到第5個字符的內容:
[root@localhost Desktop]# cut -c 1-5 cut_data
將上面文件內容改為:
No|Name|Score
1|zhang|20
2|li|80
2|wang|90
4|sun|60
2 輸出第一字段和第三字段內容
說明:因為這里是以 | 作為分隔的所以在用分隔條件時需要加上轉義符 ** ,所以是 -d| 。整個命令解釋是:將cut_data整個文件的內容作為標準輸入到cut語句中,以 | 為分界符(可知分成了3個域),剪切出第1和3域。
命令和輸出如下:
[root@localhost Desktop]# cat cut_data | cut -d\| -f 1,3
No|Score
1|20
2|80
2|90
4|60
uniq命令
新建文件uniq_data.txt 并且內容寫:
Welcome to Linux
Windows
Windows
Mac
Mac
Linux
1 使用uniq命令輸出去重后的結果
命令及輸出結果:
[root@localhost Desktop]# uniq uniq_data.txt
Welcome to Linux
Windows
Mac
Linux
注意:默認是去重
2 使用uniq命令只輸出重復的行
命令及輸出結果:
[root@localhost Desktop]# uniq -d uniq_data.txt
Windows
Mac
3 使用uniq命令統計重復的次數
命令及結果:
[root@localhost Desktop]# uniq -c uniq_data.txt
1 Welcome to Linux
2 Windows
2 Mac
1 Linux
注意數字代表重復個數
sort命令
例:給定文件num.txt, args.txt
內容:
num.txt:
1
3
5
2
4
注意第一行有一個空格。
args.txt內容:
args1
args2
args4
args4
args3
1 對num.txt排序,并且將結果輸出到sorted_num.txt中
首先創建文件寫入內容不用說了。
命令及結果:
[root@localhost Desktop]# sort -n num.txt > sorted_num.txt
1
2
3
4
5
注意: -b 參數是不管開頭的空白,但這里不加這個參數好像也行。
2 對args.txt排序,并且將結果輸出到sorted_args.txt中
命令及顯示結果:
[root@localhost Desktop]# cat sorted_args.txt
[root@localhost Desktop]# cat sorted_args.txt
args1
args2
args3
args4
args4
3 對args.txt和num.txt排序,并將結果輸出到sorted_merge.txt中
命令及結果:
[root@localhost Desktop]# sort -n args.txt num.txt > sorted_merge.txt
[root@localhost Desktop]# cat sorted_merge.txt
args1
args2
args3
args4
args4
1
2
3
4
5
4 對args.txt排序后去重輸出合并sorted_args.txt和sorted_num.txt且輸出給定文件info.txt按第二列作為key進行排序
命令及結果:
[root@localhost Desktop]# sort args.txt | uniq | cat sorted_args.txt sorted_num.txt > info.txt | sort -k 2
注意:這個命令本人不確定對不對,應該與描述的命令一樣
tr命令
1 將后14個英文字母變成大寫
如下命令及結果:
[root@localhost Desktop]# tr m-z M-Z
abcdefghijklmnopqrstuvwxyz
abcdefghijklMNOPQRSTUVWXYZ
2 將文件中數字變為空字符
aaa.txt中寫入:
hello 123 world 456
命令及結果:
[root@localhost Desktop]# cat aaa.txt | tr 0-9 " "-" "
hello world
注意:" “-” " 。 ""號中間有個空格
結束
原文鏈接:https://blog.csdn.net/fuyuo/article/details/125823897
相關推薦
- 2022-06-12 C#泛型接口的協變和逆變_C#教程
- 2022-06-14 C#實現加密的幾種方法介紹_C#教程
- 2022-09-07 redis?protocol通信協議及使用詳解_Redis
- 2022-10-15 Go?Excelize?API源碼解讀GetSheetViewOptions與SetPageLayo
- 2022-08-30 c語言學習——動態內存分配
- 2022-10-04 正則表達式中關于對原生字符串的簡單理解_正則表達式
- 2024-03-05 layui彈出層的表單驗證(form表單自帶的驗證不執行)
- 2022-06-15 go語言定時器Timer及Ticker的功能使用示例詳解_Golang
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支