文件上传下载,命令之wget / curl / which / sort / uniq / cut / wc /tr /sed
命令
1.文件的上传下载
需要下载安装包
[root@oldboyedu ~]# yum install -y lrzsz #安装包
rz:只能上传文件 (直接拖拽文件)
1)不支持上传超过4G的文件
2)不支持断点续传
rz不能上传目录,需要把目录压缩打包才可以上传
sz:下载文件
示例:sz filename
2.从外网下载文件wget
wget | 文件下载 |
---|---|
-O | 指定地址下载,更改名称 |
-T | 超时时间 |
-q | 安静下载(关闭wget输出) |
--spider | 网络爬虫 |
示例:
Wget http://www.baidu.com
如果没有,则安装:yum install -y wget
-O:指定下载的路径,可以改名
3.curl文件下载
-o:指定下载的路径,可以改名
示例:
Curl -o http://www.baidu.com
4.查找命令which
Which查找系统目录下的命令(绝对路径)
[root@centos7 ~]# which rm
alias rm='rm -i'
/usr/bin/rm
了解
type -a 也可以查命令的路径
whereis也可以查命令的路径
[root@centos7 ~]# whereis rm
rm: /usr/bin/rm /usr/share/man/man1/rm.1.gz
[root@centos7 ~]# type -a rm
rm is aliased to `rm -i'
rm is /usr/bin/rm
[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
5.字符处理命令-排序sort
-t | 指定分隔符 |
---|---|
-k | 指定第几列的内容(按分隔符),不指定分隔符,默认是空格为分隔符 |
-n | 按照阿拉伯数字的大小顺序排序 |
-r | 倒叙排序 |
输入文件
[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
6.字符处理-去重uniq
去重相邻行,不相邻不会去重
-c | 显示去重后的数量(count) |
---|---|
-d | 只显示重复的行 |
-u | 只显示不重复的行 |
输入内容:
[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
7.字符处理-截取cut
-d | 指定分隔符 |
---|---|
-f | 指定第几列 |
-c | 根据字符来取数据 |
输入内容
[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
8.字符处理-统计wc
-l | 统计行数 |
---|---|
-c | 统计字节数 |
-w | 统计单词次数,也就是列数 |
示例:
[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
9.tr替换
[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
10. sed 文本处理工具,三剑客之一
选项:
-n | 取消默认输出 |
---|---|
p | 打印当前内容 |
d | 删除当前行 |
i | 修改文件的内容 |
s | 替换 |
g | 表示全局 |
; | 多条命令分隔符,取不连续的多行 |
-r | 支持扩展正则表达式使用 |
[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 参数,输入后没有任何结果显示,但查看原文件,会发现变了
10. awk 去列,统计,计算。
文本处理工具,三剑客之一
选项:
! | 取反 ’!/ /' |
---|---|
NR | 取行'{print $0,NR}' |
$ | 取列 '{print ,NR}' |
d | 删除 '/ /d' |
$NF | 最后一列 |
$0 | 整行内容 |
显示内容 | |
! | 取反 |
column-t | 对齐 |
[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
取ip地址
[root@centos7 ~]# ip a s ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
link/ether 00:0c:29:d9:4a:0d brd ff:ff:ff:ff:ff:ff
inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::acc3:5abb:9655:e2d5/64 scope link noprefixroute
valid_lft forever preferred_lft forever
#先取第三行:
[root@centos7 ~]# ip a s ens33 | awk 'NR==3'
inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute ens33
#把/换成空格,取第3行,第6列
[root@centos7 ~]# ip a s ens33 | awk -F '[ /]' 'NR==3{print $6}'
10.0.0.100
文件上传下载,命令之wget / curl / which / sort / uniq / cut / wc /tr /sed的更多相关文章
- 【转帖】linux sort,uniq,cut,wc,tr,xargs命令详解
linux sort,uniq,cut,wc,tr,xargs命令详解 http://embeddedlinux.org.cn/emb-linux/entry-level/201607/21-5550 ...
- ftp文件上传下载命令
介绍:从本地以用户wasqry登录的机器1*.1**.21.67上通过ftp远程登录到ftp服务器上,登录用户名是lte****,以下为使用该连接做的实验. 查看远程ftp服务器上用户lte**** ...
- linux CentOS 安装rz和sz命令 lrzsz 实现windows和linux之间的文件上传 下载
https://blog.nbhao.org/1902.html https://bbs.csdn.net/topics/391989523 https://www.cnblogs.com/zhoul ...
- 一、手把手教你docker搭建fastDFS文件上传下载服务器
在搭建fastDFS文件上传下载服务器之前,你需要准备的有一个可连接的linux服务器,并且该linux服务器上已经安装了docker,若还有没安装docker的,先百度自行安装docker. 1.执 ...
- Selenium2学习-039-WebUI自动化实战实例-文件上传下载
通常在 WebUI 自动化测试过程中必然会涉及到文件上传的自动化测试需求,而开发在进行相应的技术实现是不同的,粗略可划分为两类:input标签类(类型为file)和非input标签类(例如:div.a ...
- 【FTP】FTP文件上传下载-支持断点续传
Jar包:apache的commons-net包: 支持断点续传 支持进度监控(有时出不来,搞不清原因) 相关知识点 编码格式: UTF-8等; 文件类型: 包括[BINARY_FILE_TYPE(常 ...
- centos 6.5下安装文件上传下载服务
centos 6.5下安装文件上传下载服务 由于每次在CentOS中要下载一些配置文件到物理机,和上传一些文件到服务器,导致来回的开启ftp软件有点麻烦,这里我们可以使用文件上传下载服务,来解决上传和 ...
- Linux系统简单易用的上传下载命令rz和sz
一)安装方法汇总 1.安装方法(推荐) yum install lrzsz -y 2.在安装Linux系统时选中"DialupNetworking Support"组包 3.安装系 ...
- python3 + selenium 之文件上传下载
文件上传 文件上传下载的联系html: uplad.html <html> <head> <meta http-equiv="content-type" ...
随机推荐
- MVC下载文件方式 包括网络地址文件
MVC下载文件方式 方式一: public FileStreamResult DownFile(string filePath, string fileName){ string absol ...
- [转]Todd.log - a place to keep my thoughts on programming 分布式架构中的幂等性
Todd.log - a place to keep my thoughts on programming 理解HTTP幂等性 基于HTTP协议的Web API是时下最为流行的一种分布式服务提供方式. ...
- MySQL查询优化方法总结
1.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描. 2.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉 ...
- WAMP安装提示缺少 msvcr100.dll文件解决方法
WAMP安装提示缺少wamp msvcr100.dll文件解决方法 因为wamp基于vs c++2010开发,需要提前安装这个组件才可以正常运行 微软官方组件下载地址: 32位:http://www. ...
- db2疑难解决
http://www-01.ibm.com/support/knowledgecenter/?lang=zh#!/SSEPGG_9.5.0/com.ibm.db2.luw.messages.sql.d ...
- ThinkPHP笔记——开启debug调试模式
debug+trace模式可以查看开发过程中TP的错误信息,可以更好地帮助开发者debug.但是debug模式的开启还不是简单的在配置文件中中设置就可以的,经过查资料摸索,找到一种有效的方法. 首先在 ...
- AutoWidthInput
import React from 'react'; import PropTypes from 'prop-types'; class AutoWidthInput extends React.Co ...
- VIM+ctags+cscope用法
使用vim + cscope/ctags,就能够实现Source Insight的功能,可以很方便地查看分析源代码. 关键词: vim, cscope, ctags, tags 1. 查看vi ...
- Unicode与ASCiI之间有什么区别?java当中的转义字符 Character类的使用 String类的使用
ASCII码 称为 美国标准信息交换码 (American standard code of Information Interchange) 其中一共有多少个码?2的7次幂 128个 Unicode ...
- (2) html 语义化
HTML语义化标签 1 什么是语义化标签? 通过标签判断内容语义,例如根据h1标签判断出内容是标题,根据 p 判断内容是段落.input 标签是输入框等. 2 为什么要标签语义化? 1.搜素引擎友好 ...