文件管理之:联网下载文件(wget、curl)文件上传与下载(rz、sz)
1.wget、curl联网下载文件
wget:联网下载文件
CentOS7 系统最小化安装默认没有wget命令,需要进行安装
[root@oldboyedu ~]# yum install wget -y
- 用法:默认下载到当前目录,下载时复制下载的资源
[root@oldboyedu ~]# wget http://fj.xuliangwei.com/public/weixin.py
- -O 指定保存的位置,并重命名,如果不想重命名只想修改路径,需带上原有名称
[root@oldboyedu ~]# wget http://fj.xuliangwei.com/public/weixin.py
curl:在线查看网络上的资源
[root@oldboyedu ~]# curl http://fj.xuliangwei.com/public/weixin.py
-o 将内容保存至本地,并重命名(如果没有明确指定路径,则表示当前目录)
- 重命名下载文件:
[root@oldboyedu ~]# curl -o wei.txt http://fj.xuliangwei.com/public/weixin.py
- 将资源保存到指定路径
[root@oldboyedu ~]# curl -o /opt/weixin.py http://fj.xuliangwei.com/public/weixin.py
PS: 通常情况下我们推荐使用wget下载,但由于系统很多时候默认没有安装wget 会偶尔使用一下curl
练习: 使用两种方式下载如下的两个文件
1.wget保存至本地 /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@oldboyedu ~]# wget -O /etc/yum.repos.d/CentOS�
Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
2.curl保存至本地 /etc/yum.repos.d/epel.repo
http://mirrors.aliyun.com/repo/epel-7.repo
[root@oldboyedu ~]# curl -o /etc/yum.repos.d/epel.repo
http://mirrors.aliyun.com/repo/epel-7.repo
3.最后执行一条命令检查 yum makecache
2.rzsz上传下载文件
安装命令 yum install lrzsz -y
rz 上传文件:将windos系统中的文件上传到linux
输入rz,选择需要上传的文件
-
直接拖拽
只能上传文件,不支持上传文件夹,不支持大于4个G上传,也不支持断点续传
sz 下载文件:将linux系统中的文件下载到windos
-
输入sz,选择需要下载的文件
只能下载文件 (任意单个文件),不支持下载文件夹
文件管理之:文件或命令查找(which、whereis、find)
命令查找
1.which 查找一个命令的绝对路径
[root@oldboyedu ~]# which cp alias cp='cp -i' /usr/bin/cp
2.whereis 查找一个命令的绝对路径、帮助手册、等
[root@oldboyedu ~]# whereis cp cp: /usr/bin/cp /usr/share/man/man1/cp.1.gz
- -b /仅显示命令所在的路径
[root@oldboyedu ~]# whereis -b cp cp: /usr/bin/cp
3.type 于内核相关的一些命令,使用which whereis是无法查询到,需要使用type命令查询
- -a #查看命令的绝对路径(包括别名)
[root@oldboyedu ~]# type -a cp cp is aliased to `cp -i' cp is /usr/bin/cp
文件管理之:文件内容处理命令(sort、uniq、cut、sed、awk、wc)
1.sort 对无序文件进行排序
[root@oldboyedu ~]# sort file.txt
a:4
b:3
c:2
d:1
e:5
f:11
- -r 倒序
[root@oldboyedu ~]# sort -r file.txt
f:11
e:5
d:1
c:2
b:3
a:4
- -t 指定分隔符
- -k 指定第几列(指定1,1 3.1,3.3
[root@oldboyedu ~]# sort -t ":" -k2 file.txt
d:1
f:11
c:2
b:3
a:4
e:5
- -n 按数字排列顺序
[root@oldboyedu ~]# sort -t ":" -nk2 file.txt d:1 c:2 b:3 a:4 e:5 f:11
2.uniq 去重
- 需要和sort一起使用, 先使用sort排序, 不能去除非连续的相同的文本让重复内容连续在一起
[root@oldboyedu ~]# sort lx2 |uniq 123 abc
- -c 能统计出文件中每行内容重复的次数
[root@oldboyedu ~]# sort lx2 |uniq -c 2 123 3 abc
3.cut awk截取字段
awk
- -F 列出分隔符
[root@oldboyedu ~]# awk '{print
5}' file2.txt | awk -F "," '{print
2}' xlw 552408925
- 还可以筛选文本内容等
cut 截取字段
-d 指定分隔符
-f 数字,取第几列 –f3,6三列和6列
-c 按字符取(空格也算
[root@oldboyedu ~]# cut -d " " -f 2,5 file2.txt | awk -F "," '{print
2}'
xlw 552408925
sed 替换文本内容
sed 's#,##g' file2.txt | awk '{print
5}'
xlw 552408925
4.wc 统计行号
- -l 显示文件行数
[root@oldboyedu ~]# grep "nologin$" /etc/passwd | wc -l
18