[root@oldboyedu ~]# yum install -y lrzsz #安装包
rz:上传文件 (直接拖拽文件)
1)不支持上传超过4G的文件
2)不支持断点续传
sz:下载文件
示例:sz filename
示例:
Wget http://www.baidu.com
如果没有,则安装:yum install -y wget
-O:指定下载的路径,可以改名
-o:指定下载的路径,可以改名
示例:
Curl -o http://www.baidu.com
Which查找系统mv目录下的命令(绝对路径)
[root@oldboyedu ~]# which mv
alias
/usr/bin/mv
Type了解
[root@oldboyedu ~]# type -a ls
ls is aliased to `ls --color=auto'
ls is /usr/bin/ls
[root@oldboyedu ~]# type -a for
for is a shell keyword
输入文件
[root@centos7 ~]# cat >> sort.txt <<eof
\> A:d:8
\> E:x:2
\> B:c:6
\> eof
排序文件
[root@centos7 ~]# sort sort.txt
A:d:8
B:c:6
E:x:2
按照字母小写顺序排序
[root@centos7 ~]# sort -t ':' -k 2 sort.txt
B:c:6
A:d:8
E:x:2
按照字母小写顺序排序
[root@centos7 ~]# sort -t ':' -k 2 -n sort.txt
A:d:8
B:c:6
E:x:2
按照字母小写倒叙
[root@centos7 ~]# sort -t ':' -k 2 -n -r sort.txt
E:x:2
B:c:6
A:d:8
去重相邻行,不相邻不会去重
输入内容:
[root@centos7 ~]# cat >>unip.txt <<eof
\> abc
\> abc
\> 123
\> eof
文件去重(没有排序无法去重)
[root@centos7 ~]# uniq uniq.txt
abc
123
abc
123
排序文件
[root@centos7 ~]# sort uniq.txt
123
123
abc
Abc
先排序文件,后去重
[root@centos7 ~]# sort uniq.txt |uniq
123
abc
先排序文件,后去重并显示去重后的数量
[root@centos7 ~]# sort uniq.txt |uniq -c
2 123
2 abc
输入内容
[root@centos7 ~]# cat >>info.txt <<eof
\> I’m gjy,20 years old qq 861962063
\> eof
#以空格为分隔符,截取第二个,第六个字符
[root@centos7 ~]# cut -d ' ' -f 2,6 info.txt
gjy,20 861962063
以空格为分隔符,截取第二个,第六个,再以逗号为分隔符,截取第一个第二个
[root@centos7 ~]# cut -d ' ' -f 2,6 info.txt |cut -d ',' -f 1,2
gjy,20 861962063
[root@centos7 ~]# cut -d ' ' -f 2,6 info.txt |cut -c 1-3,8-16
gjy861962063
示例:
[root@centos7 ~]# wc /etc/services
11176 61033 670293 /etc/services
统计字节:
[root@centos7 ~]# wc -c /etc/services
670293 /etc/services l
统计行数
[root@centos7 ~]# wc -l /etc/services
11176 /etc/services
统计单词
[root@centos7 ~]# wc -l /etc/services
11176 /etc/services
[root@centos7 ~]# tr '1' 'o' <uniq.txt #1就全部替换成了o
abc
o23
abc
o23
[root@centos7 ~]# echo "1" >>uniq.txt #再追加一个 1
[root@centos7 ~]# tr '123' '0ld' <uniq.txt #单个对单个的替换
abc
0ld
abc
0ld
0
选项:
[root@centos7 ~]# cat>sed.txt<<'EOF' #输入文件内容
> 101,$oldboy,CEO
> 102,$zhangyao,CTO
> 103,$Alex,COO
> 104,$yy,CFO
> 105,$feixue,CIO
> 106,$lidao,UFO
> EOF
[root@centos7 ~]# cat sed.txt #查看文件
101,$oldboy,CEO
102,$zhangyao,CTO
103,$Alex,COO
104,$yy,CFO
105,$feixue,CIO
106,$lidao,UFO
[root@centos7 ~]# sed -n '2p' sed.txt #取出第二行
102,$zhangyao,CTO
[root@centos7 ~]# sed -n '2,4p' sed.txt #取出第二到四行
102,$zhangyao,CTO
103,$Alex,COO
104,$yy,CFO
[root@centos7 ~]# sed -n '2p;4p' sed.txt #取出第二行和第四行
104,$yy,CFO
[root@centos7 ~]# sed '2d' sed.txt # 删除第二行
101,$oldboy,CEO
103,$Alex,COO
104,$yy,CFO
105,$feixue,CIO
106,$lidao,UFO
按字符串取
[root@centos7 ~]# sed -n '/oldboy/p' sed.txt #取出oldboy所在的一行
101,$oldboy,CEO
[root@centos7 ~]# sed -nr '/oldboy|feixue/p' sed.txt #同时取出oldboy和feixue所在的一行
101,$oldboy,CEO
105,$feixue,CIO
[root@centos7 ~]# sed '/oldboy/d' sed.txt #删除oldboy所在的一行,相当于取反
102,$zhangyao,CTO
103,$Alex,COO
104,$yy,CFO
105,$feixue,CIO
106,$lidao,UFO
[root@centos7 ~]# sed 's#lidao#qiudao#g' sed.txt #替换‘s###g' ,有结果显示,但是原文件没变
101,$oldboy,CEO
102,$zhangyao,CTO
103,$Alex,COO
104,$yy,CFO
105,$feixue,CIO
106,$qiudao,UFO
[root@centos7 ~]# sed -i 's#lidao#qiudao#g' sed.txt # 加上-i 参数,输入后没有任何结果显示,但查看原文件,会发现变了
!
取反 '!/ /'
NR
取行 '{print $0,NR}'
$
取列 '{print ,NR}'
d
删除 '/ /d'
[root@centos7 ~]# awk '{print $0,NR}' sed.txt
101,$oldboy,CEO 1
102,$zhangyao,CTO 2
103,$Alex,COO 3
104,$yy,CFO 4
105,$feixue,CIO 5
106,$qiudao,UFO 6
取行:
[root@centos7 ~]# awk 'NR==2,NR==4' sed.txt
102,$zhangyao,CTO
103,$Alex,COO
104,$yy,CFO
[root@centos7 ~]# awk 'NR==2,NR==4' sed.txt
102,$zhangyao,CTO
103,$Alex,COO
104,$yy,CFO
[root@centos7 ~]# awk 'NR>1&& NR<5' sed.txt
102,$zhangyao,CTO
103,$Alex,COO
104,$yy,CFO
[root@centos7 ~]# awk 'NR>=2 && NR<=4' sed.txt
102,$zhangyao,CTO
103,$Alex,COO
104,$yy,CFO
过滤
[root@centos7 ~]# awk '/oldboy/' awk.txt
101,$oldboy,CEO
[root@centos7 ~]# awk '/oldboy|qiudao/' awk.txt
101,$oldboy,CEO
106,$qiudao,UFO