1.使用whereis 查找 locate命令
使用which查找whereis命令
使用locate查找rm命令
[root@localhost ~]# whereis locate
locate: /usr/bin/locate /usr/share/man/man1/locate.1.gz
[root@localhost ~]# which whereis
/usr/bin/whereis
[root@localhost ~]# locate rm
在第一次使用locate前记得先执行下updatedb命令来生成索引数据库
2.find命令使用:
使用find命令在当前路径下查找所有的普通文件
使用find命令查找当前路径下的file1.txt,file2.txt,file3.txt
使用find命令查找文件所有者为root的普通文件
使用find命令查找修改时间在1天以内的普通文件
[root@localhost ~]# find . -type f
./.bash_logout
./.bash_profile
./.bashrc
./.cshrc
./.tcshrc
./anaconda-ks.cfg
./.cache/dconf/user
./.dbus/session-bus/5ffac4ca2441450595d19730f44b4e93-9
./.config/pulse/5ffac4ca2441450595d19730f44b4e93-device-volumes.tdb
./.config/pulse/5ffac4ca2441450595d19730f44b4e93-stream-volumes.tdb
./.config/pulse/5ffac4ca2441450595d19730f44b4e93-card-database.tdb
./.config/pulse/cookie
./.config/pulse/5ffac4ca2441450595d19730f44b4e93-default-sink
./.config/pulse/5ffac4ca2441450595d19730f44b4e93-default-source
./initial-setup-ks.cfg
./.esd_auth
./.bash_history
./video_1756187
./link_test/link_file
./link_test/hard_link
./link_test/symb_link
./.text2.txt.swp
./.text2.txt.swo
./.Xauthority
./newtext1.txt
./text2.txt
./.viminfo
./text111.txt
./text111_hard.txt
./pipe
./data.txt
./pipe_data.txt
[root@localhost ~]# find . -name file1.txt
./file1.txt
[root@localhost ~]# find . -name file2.txt
./file2.txt
[root@localhost ~]# find . -name file3.txt
./file3.txt
[root@localhost ~]# find . -group root -a -type f
./.bash_logout
./.bash_profile
./.bashrc
./.cshrc
./.tcshrc
./anaconda-ks.cfg
./.cache/dconf/user
./.dbus/session-bus/5ffac4ca2441450595d19730f44b4e93-9
./.config/pulse/5ffac4ca2441450595d19730f44b4e93-device-volumes.tdb
./.config/pulse/5ffac4ca2441450595d19730f44b4e93-stream-volumes.tdb
./.config/pulse/5ffac4ca2441450595d19730f44b4e93-card-database.tdb
./.config/pulse/cookie
./.config/pulse/5ffac4ca2441450595d19730f44b4e93-default-sink
./.config/pulse/5ffac4ca2441450595d19730f44b4e93-default-source
./initial-setup-ks.cfg
./.esd_auth
./.bash_history
./video_1756187
./link_test/link_file
./link_test/hard_link
./link_test/symb_link
./.text2.txt.swp
./.text2.txt.swo
./.Xauthority
./newtext1.txt
./text2.txt
./.viminfo
./text111.txt
./text111_hard.txt
./pipe
./data.txt
./pipe_data.txt
./file1.txt
./file2.txt
./file3.txt
[root@localhost ~]# find . -mtime -1
.
./.config/pulse/5ffac4ca2441450595d19730f44b4e93-default-sink
./.config/pulse/5ffac4ca2441450595d19730f44b4e93-default-source
./.bash_history
./.text2.txt.swp
./.text2.txt.swo
./.Xauthority
./newtext1.txt
./text2.txt
./.viminfo
./test2
./test2/test1
./test2/test1/test2
./test2/test1/test2/test3
./text111.txt
./text111_symb.txt
./text111_hard.txt
./pipe
./data.txt
./pipe_data.txt
./file1.txt
./file2.txt
./file3.txt
3.cut命令使用:
给定文件cut_data.txt且内容为:
No Name Score
1 zhang 20
2 li 80
3 wang 90
4 sun 60
使用默认定界符切割文件内容,且输出切割后的第一个字段
切割文件内容,且输出切割后的第一个字段和第三个字段
按字节切割:输出切割的第一个字节到第10个字节的内容
按字符切割:输出切割后的第一个字符和第5个字符的内容
按指定分界符去切割:内容如下, 输出第一个字段和第三个字段内容
No|Name|Score
1|zhang|20
2|li|80
3|wang|90
4|sun|60
[root@localhost ~]# cut -d" " -f1 cut_data.txt
No
1
2
3
4
[root@localhost ~]# cut -d" " -f1,3 cut_data.txt
No Score
1 20
2
3 90
4 60
[root@localhost ~]# cut -b1-10 cut_data.txt
No Name Sc
1 zhang 20
2 li 80
3 wang 90
4 sun 60
[root@localhost ~]# cut -c1,5 cut_data.txt
Na
1a
2
3n
4n
[root@localhost ~]# cut -d"|" -f1,3 cut_data.txt
No|Name|Score
1|zhang|20
2|li|80
3|wang|90
4|sun|60
4.uniq命令使用: 新建文件uniq_data.txt,文件内容为
Welcome to Linux
Windows
Windows
Mac
Mac
Linux
使用uniq命令输出去重后的结果
使用uniqmingl只输出重复的行
使用uniq命令输出不重复的行
使用uniq命令统计重复次数
[root@localhost ~]# uniq uniq_data.txt
Welcome to Linux
Windows
Mac
Linux
[root@localhost ~]# uniq -d uniq_data.txt
Windows
Mac
[root@localhost ~]# uniq -u uniq_data.txt
Welcome to Linux
Linux
[root@localhost ~]# uniq -c uniq_data.txt
1 Welcome to Linux
2 Windows
2 Mac
1 Linux
5.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中
对args.txt进行排序,且将结果输出到sorted_args.txt中
对num.txt和args.txt进行排序,且将结果输出到sorted_merge.txt中
对args.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@localhost ~]# vim num.txt
[root@localhost ~]# vim args.txt
[root@localhost ~]# sort num.txt > sorted_num.txt
[root@localhost ~]# cat sorted_num.txt
1
2
3
4
5
num.txt
[root@localhost ~]# sort args.txt > sorted_args.txt
[root@localhost ~]# cat sorted_args.txt
args1
args2
args3
args4
args4
test
[root@localhost ~]# sort num.txt args.txt > sorted_merge.txt
[root@localhost ~]# cat sorted_merge.txt
1
2
3
4
5
args1
args2
args3
args4
args4
num.txt
test
root@localhost ~]# sort -u args.txt
args1
args2
args3
args4
test
[root@localhost ~]# sort -m args.txt num.txt
num.txt
1
3
5
2
4
test
args1
args2
args4
args4
args3
[root@localhost ~]# sort -k 2 info_txt
1 zhang 20
2 li 80
3 wang 90
4 sun 60
No Name Score
6.将26个小写字母的后13个字母替换成大写字母
将hello 123 world 456中的数字替换成空字符(提示使用通配符)
将hello 123 world 456中字母和空格替换掉,只保留数字(提示使用通配符)
[root@localhost ~]# echo "abcdefghljklmnopqrstuvwxyz" | tr n-z N-Z
abcdefghljklmNOPQRSTUVWXYZ
[root@localhost ~]# echo "hello 123 world 456" | tr "[0-9]" " "
hello world
[root@localhost ~]# echo "hello 123 world 456" | tr -d -c "[0-9]"
123456[root@localhost ~]#
7.wc命令使用:
给定文件:word_count.txt,里面填充10行内容
按字节去统计
按单词去统计
按行去统计
[root@localhost ~]# wc -c word_count.txt
144 word_count.txt
[root@localhost ~]# wc -w word_count.txt
10 word_count.txt
[root@localhost ~]# wc -l word_count.txt
10 word_count.txt
528

被折叠的 条评论
为什么被折叠?



