7/30 day5-文件管理

联网下载文件(wget、curl)、文件上传与下载(rz、sz)

wget、curl联网下载文件

需要yum安装 wget   系统最小化安装 没有wget

wget

#选项: -O: 指定下载地址                       可以重命名 

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo(更换为国内的yum源)

curl  网址  ==在线浏览网站资源内容(源代码)

没有指定路径,保存在当前目录

将资源保存至指定的路径

#选项: -o: 指定下载地址

curl -o/etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/Centos-7.repo

通常情况下我们使用wget下载,但由于系统很多时候默认没有安装wget,有事用curl

检查yum makecache

#练习: 使用两种方式下载如下的两个文件

#1.wget保存至本地 /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-7.repo

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

#2.curl保存至本地 /etc/yum.repos.d/epel.repohttp://mirrors.aliyun.com/repo/epel-7.repo

curl -o/etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/Centos-7.repo

#3.最后执行一条命令检查  yum makecache

了解:kill -9  强制杀死进程

rzsz上传下载文件

yum install lrzsz -y  #不安装软件则无法执行该命令

无法直接拖拽进Linux服务器

①没有安装lrzsz

② 文件是空的

rz            #只能上传文件文件上传

sz /path/file #只能下载文件(任意单个文件) 不支持下载文件夹

文件不支持4G以上

命令查找

查找一个命令的绝对路径

当我们想执行一个命令的绝对路径时,先使用which command 查询绝对路径

which ls  #查找ls命令的绝对路径

whereis ls      //查找命令的路径、帮助手册、等

whereis -b ls    //仅显示命令所在的路径

type -a ls        #查看命令的绝对路径(包括别名)可以查内置命令

字符处理命令(sort、uniq、cut、sed、awk、wc、)

sort排序

sort [OPTION]... [FILE]...

-r:倒序

-n:按数字排序

-t:指定分隔符(默认空格)

-k:指定第几列, 指定几列几字符(指定1,1  3.1,3.3)

uniq去重

去除重复 配合sort使用

uniq [OPTION]... [INPUT] [OUTPUT]]#选项:-c  计算重复的行

#1.创建一个file.txt文件:[root@xuliangwei ~]# cat file.txtabc123abc123#2.uniq需要和sort一起使用, 先使用sort排序, 让重复内容连续在一起[root@xuliangwei ~]# cat file.txt |sort123123abcabc#3.使用uniq去除相邻重复的行[root@xuliangwei ~]# cat file.txt |sort|uniq123abc#4.-c参数能统计出文件中每行内容重复的次数[root@xuliangwei ~]# cat file.txt |sort|uniq -c      2 123      2 abc

cut截取字段

cut OPTION... [FILE]...#选项:

-d 指定分隔符

-f 数字,取第几列 –f3,6三列和6列

-c 按字符取(空格也算)

cat >>file2.txt <<EOFIm xlw, is QQ 552408925EOF

#echo "Im xlw, is QQ 552408925" >file.txt 

#过滤出文件里 xlw以及552408925

awk  '{print $2,$5}' file.txt |awk -F ',' '{print $1,$2}'


#实现上述题目几种思路

cut -d " " -f2,5 file.txt

cut -d " " -f2,5 file.txt |sed 's#,##g'

sed 's#,# #g' file.txt | awk -F " " '{print $2 " " $5}'

awk -F  "[, ]" '{print $2,$6}' file.txt

awk -F '[, ]+' '{print $2,$5}' file.txt

wc统计行号

wc [OPTION]... [FILE]...#选项:

-l显示文件行数 

-c显示文件字节

 -w显示文件单词

wc -l /etc/fstab      #统计/etc/fstab文件有多少行

wc -l /etc/services  #统计/etc/services 文件行号

#扩展方法

grep -n ".*" /etc/services  | tail -1

awk '{print NR $0}' /etc/services | tail -1

cat -n /etc/services  | tail -1

习题: 分析如下日志,统计每个域名被访问的次数。

[root@student tmp]# cat web.log http://www.xuliangwei.com/index.html

http://www.xuliangwei.com/1.html

http://post.xuliangwei.com/index.html

http://mp3.xuliangwei.com/index.html

http://www.xuliangwei.com/3.htmlhttp://post.xuliangwei.com/2.html

awk -F '/' '{print $3}' web.log|sort -rn|uniq –c

cut -d / -f3 web.log|sort -rn|uniq –c

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容