2017-08-15 每天2个Linux命令 sudo命令
sudo命令用来以其他身份来执行命令,预设的身份为root。
(1)用法:
用法: sudo [参数] [命令]
(2)功能:
功能: sudo可以针对单个命令授予临时权限。用户也可以通过su切换到root用户运行命令,su启动一个root shell允许用户运行之后的所有的命令。
1)sudo与su的不同之处:sudo仅在需要时授予用户权限,减少了用户因为错误执行命令损坏系统的可能性;
sudo也可以用来以其他用户身份执行命令。此外,sudo可以记录用户执行的命令,以及失败的特权获取。
2)提醒:在/etc/sudoers中设置了可执行sudo指令的用户。若其未经授权的用户企图使用sudo,
则会发出警告的邮件给管理员。用户使用sudo时,必须先输入密码,之后有5分钟的有效期限,超过期限则必须重新输入密码。
复制代码
[sunmeng@localhost ~]$ yum update mysql //yum的执行需要root权限
已加载插件:fastestmirror, langpacks
您需要 root 权限执行此命令。
[sunmeng@localhost ~]$ sudo yum update mysql //默认情况下sudo获得root用户的权限
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for sunmeng:
sunmeng 不在 sudoers 文件中。此事将被报告。 //此时sunmeng还没有使用sudo的权限
3)[root@localhost etc]# cat sudoers 查看/etc下的只有root才能打开的文件配置文件sudoers
复制代码
1 ## Sudoers allows particular users to run various commands as
2 ## the root user, without needing the root password.
3 ## 该文件允许特定用户像root用户一样使用各种各样的命令,而不需要root用户的密码
4 ##
5 ## Examples are provided at the bottom of the file for collections
6 ## of related commands, which can then be delegated out to particular
7 ## users or groups.
8 ## 在文件的底部提供了很多相关命令的示例以供选择,这些示例都可以被特定用户或
9 ## 用户组所使用
10 ##
11 ## This file must be edited with the 'visudo' command.
12 ## 该文件必须使用"visudo"命令编辑
13
14 ## Host Aliases
15 ## Groups of machines. You may prefer to use hostnames (perhaps using
16 ## wildcards for entire domains) or IP addresses instead.
17 ## 对于一组服务器,你可能会更喜欢使用主机名(可能是全域名的通配符)
18 ## 、或IP地址,这时可以配置主机别名
19 # Host_Alias FILESERVERS = fs1, fs2
20 # Host_Alias MAILSERVERS = smtp, smtp2
21
22 ## User Aliases
23 ## These aren't often necessary, as you can use regular groups
24 ## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname
25 ## rather than USERALIAS
26 ## 这并不很常用,因为你可以通过使用组来代替一组用户的别名
27 # User_Alias ADMINS = jsmith, mikem
28
29 ## Command Aliases
30 ## These are groups of related commands...
31 ## 指定一系列相互关联的命令(当然可以是一个)的别名,通过赋予该别名sudo权限,
32 ## 可以通过sudo调用所有别名包含的命令,下面是一些示例
33
34 ## Networking 网络操作相关命令别名
35 # Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient
36 , /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig
37 , /sbin/mii-tool
38
39 ## Installation and management of software 软件安装管理相关命令别名
40 # Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum
41
42 ## Services 服务相关命令别名
43 # Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig
44
45 ## Updating the locate database 本地数据库升级命令别名
46 # Cmnd_Alias LOCATE = /usr/bin/updatedb
47
48 ## Storage 磁盘操作相关命令别名
49 # Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe
50 , /bin/mount, /bin/umount
51
52 ## Delegating permissions 代理权限相关命令别名
53 # Cmnd_Alias DELEGATING = /usr/sbin/visudo, /bin/chown, /bin/chmod, /bin/chgrp
54
55 ## Processes 进程相关命令别名
56 # Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall
57
58 ## Drivers 驱动命令别名
59 # Cmnd_Alias DRIVERS = /sbin/modprobe
60
61 # Defaults specification
62
63 #
64 # Disable "ssh hostname sudo <cmd>", because it will show the password in clear.
65 # You have to run "ssh -t hostname sudo <cmd>".
66 # 一些环境变量的相关配置,具体情况可见man soduers
67 Defaults requiretty
68 //设为默认的目标用户,69行是系统自带的,是对所有用户的默认,如果设sunmeng为默认目标用户,则语法为:Defaults:foobar runas_default=rene (冒号必不可少)
69 Defaults env_reset
70 Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS"
71 Defaults env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"
72 Defaults env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"
73 Defaults env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"
74 Defaults env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"
75
76 Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
77
78 ## Next comes the main part: which users can run what software on
79 ## which machines (the sudoers file can be shared between multiple
80 ## systems).
81 ## 下面是规则配置:什么用户在哪台服务器上可以执行哪些命令(sudoers文件可以在多个系统上共享)
82 ## Syntax(语法):
83 ##
84 ## user MACHINE=COMMANDS 用户 登录的主机=(可以变换的身份) 可以执行的命令
85 ##
86 ## The COMMANDS section may have other options added to it.
87 ## 命令部分可以附带一些其它的选项
88 ##
89 ## Allow root to run any commands anywhere
90 ## 允许root用户执行任意路径下的任意命令
91 root ALL=(ALL) ALL
92 //第一个ALL是指网络中的主机,我们后面把它改成了主机名。第二个括号里的ALL是指目标用户,也就是以谁的身份去执行命令。最后一个ALL当然就是指命令名了。
93 ## Allows members of the 'sys' group to run networking, software,
94 ## service management apps and more.
95 ## 允许sys中户组中的用户使用NETWORKING等所有别名中配置的命令
96 # %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE
97 , DRIVERS
98
99 ## Allows people in group wheel to run all commands
100 ## 允许wheel用户组中的用户执行所有命令
101 %wheel ALL=(ALL) ALL
102
103 ## Same thing without a password
104 ## 允许wheel用户组中的用户在不输入该用户的密码的情况下使用所有命令
105 # %wheel ALL=(ALL) NOPASSWD: ALL
106
107 ## Allows members of the users group to mount and unmount the
108 ## cdrom as root
109 ## 允许users用户组中的用户像root用户一样使用mount、unmount、chrom命令
110 # %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
111
112 ## Allows members of the users group to shutdown this system
113 ## 允许users用户组中的用户关闭localhost这台服务器
114 # %users localhost=/sbin/shutdown -h now
115
116 ## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
117 ## 读取放置在/etc/sudoers.d/文件夹中的文件(此处的#不意味着这是一个声明)
118 #includedir /etc/sudoers.d
4)给普通用使用sudo命令的授权:
复制代码
visudo后得到的格式为:
账户名 主机名称=(可切换的身份) 可用的指令
//比如root账户
root ALL=(ALL) ALL
对于新增的账户就在下面加上
test ALL=(root) ALL
//允许test用sudo命令执行root的所有命令
同理对于组使用者也是一个,但是要加上%
%testgroup ALL=(root) ALL
需要注意的是:每次切换,你都需要密码才可以,使用如下命令可以避免输入密码:
test ALL=(root) NOPASSWD: ALL
复制代码
复制代码
[root@localhost sunmeng]# visudo //这里的visudo不需要任何参数,因为它是打开sudoers的专属命令
//改过的地方
## user MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
sunmeng ALL=(ALL) ALL
5)简单的测试:
复制代码
[sunmeng@localhost ~]$ ls //当前身份执行命令
Desktop Documents Downloads Music Pictures Public Templates Videos
[sunmeng@localhost ~]$ sudo ls //利用root身份执行命令
Desktop Documents Downloads Music Pictures Public Templates Videos
[sunmeng@localhost ~]$ yum update mysql //当前身份执行命令,提醒需要root身份
已加载插件:fastestmirror, langpacks
您需要 root 权限执行此命令。
[sunmeng@localhost ~]$ sudo yum update mysql //以root身份执行命令(在终端中第一次用这个命令时会提醒输入密码)
已加载插件:fastestmirror, langpacks
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
Loading mirror speeds from cached hostfile
* base: mirrors.cqu.edu.cn
* extras: mirrors.cqu.edu.cn
* updates: mirrors.cqu.edu.cn
No packages marked for update
(3)选项参数:
1) -b 在后台运行命令
2) -u user 以指定用户身份运行命令(或编辑文件)
3) -l 查看当前用户可以执行的命令
4) -v 更新用户的时间戳而不执行命令(注意:在输入密码之后,5分钟内执行sudo不需要再次输入密码。)
5) -V 显示sudo的版本信息
6) -i 以目标用户登录一个shell
(4)实例:
1)[sunmeng@localhost Desktop]$ sudo -u root yum install mysql-devel 指定用户名
复制代码
[sunmeng@localhost Desktop]$ sudo -u root yum install mysql-devel -u参数比较有用的地方是在多用户时,可以临时获得权限打开用户独占的文件
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.cqu.edu.cn
* extras: mirrors.cqu.edu.cn
* updates: mirrors.cqu.edu.cn
正在解决依赖关系
--> 正在检查事务
......
--> 解决依赖关系完成
依赖关系解决
=============================================================================================================
Package 架构 版本 源 大小
=============================================================================================================
正在安装:
mariadb-devel x86_64 1:5.5.47-1.el7_2
......
作为依赖被升级:
krb5-libs.x86_64 0:1.13.2-12.el7_2 krb5-workstation.x86_64 0:1.13.2-12.el7_2
openssl.x86_64 1:1.0.1e-51.el7_2.5 openssl-libs.x86_64 1:1.0.1e-51.el7_2.5
pcre.x86_64 0:8.32-15.el7_2.1 zlib.x86_64 0:1.2.7-15.el7
完毕!
2)sudo命令与rpm命令结合使用的几个例子
复制代码
[sunmeng@localhost Desktop]$ sudo rpm -q MySQL-embedded-5.5.28-1.linux2.6.i386.rpm
[sudo] password for sunmeng:
未安装软件包 MySQL-embedded-5.5.28-1.linux2.6.i386.rpm
[sunmeng@localhost Desktop]$ sudo rpm -qpR MySQL-embedded-5.5.28-1.linux2.6.i386.rpm
MySQL-devel
libaio.so.1
libaio.so.1(LIBAIO_0.1)
libaio.so.1(LIBAIO_0.4)
libc.so.6
libc.so.6(GLIBC_2.0)
libc.so.6(GLIBC_2.1)
libc.so.6(GLIBC_2.1.3)
libc.so.6(GLIBC_2.2)
libc.so.6(GLIBC_2.3)
libc.so.6(GLIBC_2.3.3)
libcrypt.so.1
libcrypt.so.1(GLIBC_2.0)
libdl.so.2
libdl.so.2(GLIBC_2.0)
libdl.so.2(GLIBC_2.1)
libm.so.6
libm.so.6(GLIBC_2.0)
libm.so.6(GLIBC_2.1)
libncurses.so.5
libpthread.so.0
libpthread.so.0(GLIBC_2.0)
libpthread.so.0(GLIBC_2.1)
libpthread.so.0(GLIBC_2.2)
libpthread.so.0(GLIBC_2.3.2)
librt.so.1
librt.so.1(GLIBC_2.2)
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
3)[sunmeng@localhost Desktop]$ sudo -l 列出用户可以执行的命令
复制代码
[sunmeng@localhost Desktop]$ sudo -l
匹配此主机上 sunmeng 的默认条目:
requiretty, !visiblepw, always_set_home, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC
KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE",
env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME
LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY",
secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin
用户 sunmeng 可以在该主机上运行以下命令:
(ALL) ALL
4[root@localhost Desktop]# sudo -i 以目标身份登录一个shell
[root@localhost Desktop]# sudo -i
[root@localhost ~]# sudo -i
5)[root@localhost ~]# sudo -V 显示详细的sudo的版本信息
复制代码
[root@localhost ~]# sudo -V
Sudo 版本 1.8.6p7
当前选项:--build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --program-prefix=
--disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --
sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec
--localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info
--prefix=/usr --sbindir=/usr/sbin --libdir=/usr/lib64 --docdir=/usr/share/doc/sudo-1.8.6p7 --with-
logging=syslog --with-logfac=authpriv --with-pam --with-pam-login --with-editor=/bin/vi --with-env-editor
--with-ignore-dot --with-tty-tickets --with-ldap --with-ldap-conf-file=/etc/sudo-ldap.conf
--with-selinux --with-passprompt=[sudo] password for %p: --with-linux-audit --with-sssd
Sudoers 策略插件版本 1.8.6p7
Sudoers 文件语法版本 42
Sudoers 路径:/etc/sudoers
nsswitch 路径:/etc/nsswitch.conf
ldap.conf 路径:/etc/sudo-ldap.conf
ldap.secret 路径:/etc/ldap.secret
认证方法: 'pam'
若使用了 syslog,用于记录日志的 syslog 设施:authpriv
用户认证成功时使用的 syslog 优先级:notice
用户认证不成功时使用的 syslog 优先级:alert
忽略 $PATH 中的“.”
在用户不在 sudoers 列表中时发送邮件
对每个用户/终端组合使用独立的时间戳
在用户第一次运行 sudo 时向他致辞
默认要求用户认证
root 可以运行 sudo
总是将 $HOME 设为目标用户的主目录
允许收集一些信息,以提供有用的错误消息
只允许拥有终端的用户执行 sudo
Visudo 将优先考虑 EDITOR 环境变量
设置 LOGNAME 和 USER 环境变量
日志文件折行的长度(0 则不折行):80
认证时间戳延时:5.0 分钟
密码提示延时:5.0 分钟
输入密码的尝试次数:3
要使用的 umask,或 0777 使用用户的:022
邮件程序路径:/usr/sbin/sendmail
邮件程序标志:-t
发送邮件的地址:root
邮件消息的主题行:*** SECURITY information for %h ***
密码错误消息:Sorry, try again.
认证时间戳文件夹的路径:/var/db/sudo
默认密码提示:[sudo] password for %p:
运行命令的默认用户:root
覆盖用户的 $PATH 变量的值:/sbin:/bin:/usr/sbin:/usr/bin
visudo 所使用的编辑器的路径:/bin/vi
何时为“list”伪命令请求密码:any
何时为“verify”伪命令请求密码:all
>= 3 的文件描述符将会在执行命令前关闭
将环境重设为默认的变量集
要检查完整性的环境变量:
TERM
LINGUAS
LC_*
LANGUAGE
LANG
COLORTERM
要移除的环境变量:
RUBYOPT
RUBYLIB
PYTHONUSERBASE
PYTHONINSPECT
PYTHONPATH
PYTHONHOME
TMPPREFIX
ZDOTDIR
READNULLCMD
NULLCMD
FPATH
PERL5DB
PERL5OPT
PERL5LIB
PERLLIB
PERLIO_DEBUG
JAVA_TOOL_OPTIONS
SHELLOPTS
GLOBIGNORE
PS4
BASH_ENV
ENV
TERMCAP
TERMPATH
TERMINFO_DIRS
TERMINFO
_RLD*
LD_*
PATH_LOCALE
NLSPATH
HOSTALIASES
RES_OPTIONS
LOCALDOMAIN
CDPATH
IFS
要保留的环境变量:
XAUTHORITY
_XKB_CHARSET
LINGUAS
LANGUAGE
LC_ALL
LC_TIME
LC_TELEPHONE
LC_PAPER
LC_NUMERIC
LC_NAME
LC_MONETARY
LC_MESSAGES
LC_MEASUREMENT
LC_IDENTIFICATION
LC_COLLATE
LC_CTYPE
LC_ADDRESS
LANG
USERNAME
QTDIR
PS2
PS1
MAIL
LS_COLORS
KDEDIR
INPUTRC
HISTSIZE
HOSTNAME
DISPLAY
COLORS
解析 sudoers 时使用的区域设置:C
使用 zlib 压缩 I/O 日志
用于保存输入/输出日志的目录:/var/log/sudo-io
用于保存输入/输出日志的文件:%{seq}
在分配伪终端时向 utmp/utmpx 文件中添加一条记录
本地 IP 地址和网络掩码对:
192.168.0.15/255.255.255.0
fe80::20c:29ff:fe9f:bf8b/ffff:ffff:ffff:ffff::
Sudoers I/O plugin version 1.8.6p7
2017-08-15 每天2个Linux命令 wget命令
wget命令用来从指定的URL下载文件
(1)用法:
用法: wget [参数] [URL]
(2)功能:
功能: wget命令用来从指定的URL下载文件。wget非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性,
如果是由于网络的原因下载失败,wget会不断的尝试,直到整个文件下载完毕。如果是服务器打断下载过程,
它会再次联到服务器上从停止的地方继续下载。这对从那些限定了链接时间的服务器上下载大文件非常有用。
(3)选项参数:
1) -O --output-document=FILE 将文档写入 FILE,等价于给文档指定名称
2) --limit-rate=[n] 限速下载,n为指定下载的速度
3) -c 支持断点续传
4) -i 同时下载多个文件
5) -Q [n] 当下载文件大小超过n时退出下载
6) -o 把下载信息存入日志文件
7) -P 指定目录下载
8) --tries=n 测试下载次数
(4)实例:
1)[root@localhost ~]# wget http://files.cnblogs.com/files/MenAngel/GLTools-master.zip 直接从网址下载文件
复制代码
[root@localhost ~]# wget http://files.cnblogs.com/files/MenAngel/GLTools-master.zip
--2016-06-23 02:31:01-- http://files.cnblogs.com/files/MenAngel/GLTools-master.zip
正在解析主机 files.cnblogs.com (files.cnblogs.com)... 120.26.70.206
正在连接 files.cnblogs.com (files.cnblogs.com)|120.26.70.206|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:64789 (63K) [application/x-zip-compressed]
正在保存至: “GLTools-master.zip”
100%[===================================================================>] 64,789 --.-K/s 用时 0.1s
2016-06-23 02:31:08 (444 KB/s) - 已保存 “GLTools-master.zip” [64789/64789])
[root@localhost ~]# find -name "GLTools-master.zip" //查看下载的文件存放的位置
./GLTools-master.zip
[root@localhost ~]# ls -l //默认存放在当前目录下
总用量 68
-rw-------. 1 root root 2748 6月 21 11:30 anaconda-ks.cfg
-rw-r--r--. 1 root root 64789 6月 22 01:42 GLTools-master.zip
2)[root@localhost ~]# wget -O GL_O http://files.cnblogs.com/files/MenAngel/GLTools-master.zip 为下载的文件指定别名
复制代码
[root@localhost ~]# wget -O GL_O http://files.cnblogs.com/files/MenAngel/GLTools-master.zip
--2016-06-23 02:36:33-- http://files.cnblogs.com/files/MenAngel/GLTools-master.zip
正在解析主机 files.cnblogs.com (files.cnblogs.com)... 120.26.70.206
正在连接 files.cnblogs.com (files.cnblogs.com)|120.26.70.206|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:64789 (63K) [application/x-zip-compressed]
正在保存至: “GL_O”
100%[===================================================================>] 64,789 364KB/s 用时 0.2s
2016-06-23 02:36:38 (364 KB/s) - 已保存 “GL_O” [64789/64789])
[root@localhost ~]# ll
总用量 132
-rw-------. 1 root root 2748 6月 21 11:30 anaconda-ks.cfg
-rw-r--r--. 1 root root 64789 6月 22 01:42 GL_O
-rw-r--r--. 1 root root 64789 6月 22 01:42 GLTools-master.zip
3)[root@localhost ~]# wget –limit-rate=200k http://files.cnblogs.com/files/MenAngel/GLTools-master.zip 限速下载
复制代码
[root@localhost ~]# wget --limit-rate=200k http://files.cnblogs.com/files/MenAngel/GLTools-master.zip //注意速率单位,默认情况下是bit/s
--2016-06-23 02:39:34-- http://files.cnblogs.com/files/MenAngel/GLTools-master.zip
正在解析主机 files.cnblogs.com (files.cnblogs.com)... 120.26.70.206
正在连接 files.cnblogs.com (files.cnblogs.com)|120.26.70.206|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:64789 (63K) [application/x-zip-compressed]
正在保存至: “GLTools-master.zip.2”
100%[===================================================================>] 64,789 --.-K/s 用时 0.1s
2016-06-23 02:39:40 (435 KB/s) - 已保存 “GLTools-master.zip.2” [64789/64789])
4)[root@localhost ~]# wget –limit-rate=1k -c http://files.cnblogs.com/files/MenAngel/GLTools-master.zip 断点续传
复制代码
[root@localhost ~]# wget --limit-rate=1k -c http://files.cnblogs.com/files/MenAngel/GLTools-master.zip
--2016-06-23 03:05:43-- http://files.cnblogs.com/files/MenAngel/GLTools-master.zip
正在解析主机 files.cnblogs.com (files.cnblogs.com)... 120.26.70.206
正在连接 files.cnblogs.com (files.cnblogs.com)|120.26.70.206|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:64789 (63K) [application/x-zip-compressed]
正在保存至: “GLTools-master.zip”
16% [=========> ] 10,429 1024B/s 剩余 53s ^Z
[2]+ 已停止 wget --limit-rate=1k -c http://files.cnblogs.com/files/MenAngel/GLTools-master.zip
[root@localhost ~]# wget --limit-rate=1k -c http://files.cnblogs.com/files/MenAngel/GLTools-master.zip
--2016-06-23 03:06:00-- http://files.cnblogs.com/files/MenAngel/GLTools-master.zip
正在解析主机 files.cnblogs.com (files.cnblogs.com)... 120.26.70.206
正在连接 files.cnblogs.com (files.cnblogs.com)|120.26.70.206|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 206 Partial Content
长度:64789 (63K),剩余 54236 (53K) [application/x-zip-compressed]
正在保存至: “GLTools-master.zip”
17% [=========> //直接从先前断的地方开始
5)[root@localhost ~]# wget -b url 在后台下载
6)[root@localhost ~]# tail -f wget-log.1 查看文件下载的进度(动态的)
复制代码
[root@localhost ~]# wget -b http://jsdx.down.chinaz.com/201209/MySQL-embedded-5.5.28-1.linux2.6.i386.rpm
继续在后台运行,pid 为 50518。
将把输出写入至 “wget-log.1”。
[root@localhost ~]# tail -f wget-log.1
500K .......... .......... .......... .......... .......... 0% 109K 15m12s
550K .......... .......... .......... .......... .......... 0% 148K 14m29s
600K .......... .......... .......... .......... .......... 1% 137K 13m55s
650K .......... .......... .......... .......... .......... 1% 108K 13m34s
700K .......... .......... .......... .......... .......... 1% 88.4K 13m24s
750K .......... .......... .......... .......... .......... 1% 102K 13m10s
800K .......... .......... .......... .......... .......... 1% 102K 12m57s
850K .......... .......... .......... .......... .......... 1% 81.2K 12m54s
900K .......... .......... .......... .......... .......... 1% 85.3K 12m50s
950K .......... .......... .......... .......... .......... 1% 21.7K 14m28s
1000K .......... .......... .......... .......... .......... 1% 24.1K 15m43s
1050K .......... .......... .......... .......... .......... 1% 80.4K 15m33s
1100K .......... .......... .......... .......... .......... 1% 91.4K 15m20s
1150K .......... .......... .......... .......... .......... 1% 126K 15m0s
1200K .......... .......... .......... .......... .......... 2% 127K 14m42s
1250K .......... .......... .......... .......... .......... 2% 34.4K 15m14s
1300K .......... .....^Z
7)[root@localhost ~]# wget –spider url
复制代码
[root@localhost ~]# wget --spider http://jsdx.down.chinaz.com/201209/MySQL-embedded-5.5.28-1.linux2.6.i386.rpm
开启 Spider 模式。检查是否存在远程文件。
--2016-06-23 03:20:46-- http://jsdx.down.chinaz.com/201209/MySQL-embedded-5.5.28-1.linux2.6.i386.rpm
正在解析主机 jsdx.down.chinaz.com (jsdx.down.chinaz.com)... 182.100.67.10
正在连接 jsdx.down.chinaz.com (jsdx.down.chinaz.com)|182.100.67.10|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:61904663 (59M) [audio/x-pn-realaudio-plugin]
存在远程文件。
复制代码
你可以在以下几种情况下使用--spider参数:
定时下载之前进行检查
间隔检测网站是否可用
检查网站页面的死链接
8)同时下载多个文件
cat > filelist.txt
url1
url2
url3
url4
wget -i filelist.txt
9)[root@localhost ~]# wget -o download.log ftp://magnet/?xt=urn:btih:211712D 将下载的输出信息存入日志
复制代码
[root@localhost ~]# wget -o download.log ftp://magnet/?xt=urn:btih:211712D
[root@localhost ~]# cat download.log
--2016-06-23 03:30:06-- ftp://magnet/?xt=urn:btih:211712D
=> “.listing”
正在解析主机 magnet (magnet)... 失败:未知的名称或服务。
wget: 无法解析主机地址 “magnet”
[root@localhost ~]#
10)[root@localhost ~]# wegt -P /home/sunmeng http://files.cnblogs.com/files/MenAngel/GLTools-master.zip 指定下载目录
复制代码
[root@localhost ~]# wegt -P /home/sunmeng http://files.cnblogs.com/files/MenAngel/GLTools-master.zip
bash: wegt: 未找到命令...
相似命令是: 'wget'
[root@localhost ~]# wget -P /home/sunmeng http://files.cnblogs.com/files/MenAngel/GLTools-master.zip
--2016-06-23 03:42:36-- http://files.cnblogs.com/files/MenAngel/GLTools-master.zip
正在解析主机 files.cnblogs.com (files.cnblogs.com)... 120.26.70.206
正在连接 files.cnblogs.com (files.cnblogs.com)|120.26.70.206|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:64789 (63K) [application/x-zip-compressed]
正在保存至: “/home/sunmeng/GLTools-master.zip”
100%[======================================>] 64,789 --.-K/s 用时 0.1s
2016-06-23 03:42:42 (456 KB/s) - 已保存 “/home/sunmeng/GLTools-master.zip” [64789/64789])
[root@localhost ~]# ls -l /home/sunmeng
总用量 64
drwxr-xr-x. 2 sunmeng sunmeng 6 6月 23 02:29 Desktop
drwxr-xr-x. 2 sunmeng sunmeng 6 6月 21 03:31 Documents
drwxr-xr-x. 2 sunmeng sunmeng 6 6月 21 03:31 Downloads
-rw-r--r--. 1 root root 64789 6月 22 01:42 GLTools-master.zip
drwxr-xr-x. 2 sunmeng sunmeng 6 6月 21 03:31 Music
drwxr-xr-x. 2 sunmeng sunmeng 6 6月 21 03:31 Pictures
drwxr-xr-x. 2 sunmeng sunmeng 6 6月 21 03:31 Public
drwxr-xr-x. 2 sunmeng sunmeng 6 6月 21 03:31 Templates
drwxr-xr-x. 2 sunmeng sunmeng 6 6月 21 03:31 Videos