- 使用whereis 查找 locate命令
使用which查找whereis命令
使用locate查找rm命令
[root@PPDY ~]# whereis locate
locate: /usr/bin/locate /usr/share/man/man1/locate.1.gz
[root@PPDY ~]# which whereis
/usr/bin/whereis
[root@PPDY ~]# locate rm
locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory
[root@PPDY ~]# sudo updatedb
[root@PPDY ~]# locate rm
- find命令使用:
使用find命令在当前路径下查找所有的普通文件
使用find命令查找当前路径下的file1.txt,file2.txt,file3.txt
使用find命令查找文件所有者为root的普通文件
使用find命令查找修改时间在1天以内的普通文件
[root@PPDY ~]# find . -type f
[root@PPDY ~]# find . -name "file*.txt"
[root@PPDY ~]# find . -user root
[root@PPDY ~]# find / -mtime 1 -a -type f
- cut命令使用:
给定文件cut_data.txt且内容为:
No Name Score
1 zhang 20
2 li 80
3 wang 90
4 sun 60
使用默认定界符切割文件内容,且输出切割后的第一个字段
[root@PPDY ~]# vim cut_data.txt
进入cut_data.txt后,按i a o进入输入模式,输入五行内容,
然后按ESC,进入命令模式
然后按 :进入末行模式,输入wq安全保存退出
[root@PPDY ~]# cat cut_data.txt
[root@PPDY ~]# cat cut_data.txt
NO Name Score
1 zhang 20
2 li 80
3 wang 90
4 sun 60
[root@PPDY ~]# cut -d" " -f1 cut_data.txt
NO
1
2
3
4
切割文件内容,且输出切割后的第一个字段和第三个字段
[root@PPDY ~]# cut -d" " -f1,3 cut_data.txt
NO Score
1 20
2 80
3 90
4 60
按字节切割:输出切割的第一个字节到第10个字节的内容
[root@PPDY ~]# cut -b 1-10 cut_data.txt
NO Name Sc
1 zhang 20
2 li 80
3 wang 90
4 sun 60
按字符切割:输出切割后的第一个字符和第5个字符的内容
[root@PPDY ~]# cut -c 1-5 cut_data.txt
NO Na
1 zha
2 li
3 wan
4 sun
按指定分界符去切割:内容如下, 输出第一个字段和第三个字段内容
No|Name|Score
1|zhang|20
2|li|80
3|wang|90
4|sun|60
[root@PPDY ~]# vim cut_data2.txt
进入cut_data.txt后,按i a o进入输入模式,输入五行内容,
然后按ESC,进入命令模式
然后按 :进入末行模式,输入wq安全保存退出
[root@PPDY ~]# cut -d"|" -f1,3 cut_data2.txt
No|Score
1|20
2|80
3|90
4|60
-
uniq命令使用: 新建文件uniq_data.txt,文件内容为
Welcome to Linux
Windows
Windows
Mac
Mac
Linux使用uniq命令输出去重后的结果
[root@PPDY ~]# vim uniq_data.txt
进入uniq_data.txt后,按i a o进入输入模式,输入六行内容,
然后按ESC,进入命令模式
然后按 :进入末行模式,输入wq安全保存退出
[root@PPDY ~]# uniq uniq_data.txt
Welcome to Linux
Windows
Mac
Linux
使用uniqmingl只输出重复的行
[root@PPDY ~]# uniq -d uniq_data.txt
Windows
Mac
使用uniq命令输出不重复的行
[root@PPDY ~]# uniq -d uniq_data.txt
使用uniq命令统计重复次数
[root@PPDY ~]# 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
test
args1
args2
args4
args4
args3
对num.txt进行排序,且将结果输出到sorted_num.txt中
[root@PPDY ~]# vim num.txt
[root@PPDY ~]# sort -n num.txt >> sorted_num.txt
[root@PPDY ~]# cat sorted_num.txt
1,3,5,2,4
对args.txt进行排序,且将结果输出到sorted_args.txt中
[root@PPDY ~]# sort args.txt >> sorted_args.txt
[root@PPDY ~]# cat sorted_args.txt
对num.txt和args.txt进行排序,且将结果输出到sorted_merge.txt中
对args.txt排序后去重输出
[root@PPDY ~]# sort -n num.txt >> sorted_merge.txt
[root@PPDY ~]# sort args.txt >> sorted_merge.txt
[root@PPDY ~]# cat sorted_merge.txt
合并sorted_args.txt和sorted_num.txt且输出
给定文件info_txt:按第二列作为key进行排序
No Name Score
1 zhang 20
2 li 80
3 wang 90
4 sun 60
[root@PPDY ~]# sort -t" " -k2 cut_data.txt
- 将26个小写字母的后13个字母替换成大写字母
将hello 123 world 456中的数字替换成空字符(提示使用通配符)
将hello 123 world 456中字母和空格替换掉,只保留数字(提示使用通配符)
[root@PPDY ~]# tr n-z N-Z
abcdefghijklmnopqrstuvwxyz
abcdefghijklmNOPQRSTUVWXYZ
^C
[root@PPDY ~]# vim tr_data.txt
[root@PPDY ~]# cat tr_data.txt | tr 1-6 " "
hello world
[root@PPDY ~]# cat tr_data.txt | tr -c 1-6 " "
123 456
- wc命令使用:
给定文件:word_count.txt,里面填充10行内容
按字节去统计
按单词去统计
按行去统计
[root@PPDY ~]# vim word_count.txt
[root@PPDY ~]# wc -c word_count.txt
51 word_count.txt
[root@PPDY ~]# wc -w word_count.txt
10 word_count.txt
[root@PPDY ~]# wc -l word_count.txt
10 word_count.txt