欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

文件上传下载,命令之wget / curl / which / sort / uniq / cut / wc

程序员文章站 2023-01-01 12:29:43
[toc] 命令 1.文件的上传下载 2.从外网下载文件wget | wget | 文件下载 | | | | | O | 指定地址下载,更改名称 | | T | 超时时间 | | q | 安静下载(关闭wget输出) | | spider | 网络爬虫 | 3.curl文件下载 4.查找命令whic ......

目录

命令

1.文件的上传下载

[root@oldboyedu ~]# yum install -y lrzsz    #安装包

rz:上传文件 (直接拖拽文件)
    1)不支持上传超过4g的文件
    2)不支持断点续传
        
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查找系统mv目录下的命令(绝对路径)

[root@oldboyedu ~]# which mv
alias mv='mv -i'
/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

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)
输入内容:
[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