目录:
1.useradd、passwd
2.ln
3.wget
4.pidof
5.kill
6.killall
常用系统工作命令
增加用户
useradd、passwd终端命令结合使用,如下
root@ubuntu6:~# useradd lixiang
root@ubuntu6:~# passwd lixiang
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@ubuntu6:~#
链接
硬链接则透过文件系统的inode来产生新档名,而不是产生新档案。
软链接可以看作是Windows中的快捷方式,可以让你快速链接到目标档案或目录。
创建方法都很简单:
软链接(符号链接) ln -s source target
硬链接 (实体链接)ln source target
wget命令
wget命令用于在终端中下载网络文件,格式为“wget [参数] 下载地址”。
参数 作用
-b 后台下载模式
-P 下载到指定目录
-t 最大尝试次数
-c 断点续传
-p 下载页面内所有资源,包括图片、视频等
-r 递归下载
lantiancheng@ubuntu1:~/code$ wget https://www.linuxprobe.com/docs/LinuxProbe.pdf
--2019-05-17 10:52:09-- https://www.linuxprobe.com/docs/LinuxProbe.pdf
Resolving www.linuxprobe.com (www.linuxprobe.com)... 113.207.34.227
Connecting to www.linuxprobe.com (www.linuxprobe.com)|113.207.34.227|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 20105266 (19M) [application/pdf]
Saving to: `LinuxProbe.pdf'
100%[=================================================================================================================>] 20,105,266 5.01M/s in 7.1s
2019-05-17 10:52:16 (2.69 MB/s) - `LinuxProbe.pdf' saved [20105266/20105266]
lantiancheng@ubuntu1:~/code$
递归下载
使用wget命令递归下载www.linuxprobe.com网站内的所有页面数据以及文件,下载完后会自动保存到当前路径下一个名为www.linuxprobe.com的目录中。执行该操作的命令为wget -r -p https://www.linuxprobe.com,该命令的执行结果如下。
lantiancheng@ubuntu1:~/code$ wget -r -p https://www.linuxprobe.com
--2017-08-24 19:31:41-- https://www.linuxprobe.com/
Resolving www.linuxprobe.com... 106.185.25.197
Connecting to www.linuxprobe.com|106.185.25.197|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: 'www.linuxprobe.com/index.html'
………………省略下载过程………………
pidof命令
pidof命令用于查询某个指定服务进程的PID值,格式为“pidof [参数] [服务名称]”。
每个进程的进程号码值(PID)是唯一的,因此可以通过PID来区分不同的进程。例如,可以使用如下命令来查询本机上bash服务程序的PID:
lantiancheng@ubuntu1:~/code$ pidof bash
31694
lantiancheng@ubuntu1:~/code$
kill命令
kill命令用于终止某个指定PID的服务进程,格式为“kill [参数] [进程PID]”。
lantiancheng@ubuntu1:~/code$ kill 31694
killall命令
killall命令用于终止某个指定名称的服务所对应的全部进程,格式为:“killall [参数] [服务名称]”。
系统状态检测命令
uname命令
uname命令用于查看系统内核与系统版本等信息,格式为“uname [-a]”。
在使用uname命令时,一般会固定搭配上-a参数来完整地查看当前系统的内核名称、主机名、内核发行版本、节点名、系统时间、硬件名称、硬件平台、处理器类型以及操作系统名称等信息。
lantiancheng@ubuntu1:~/code$ uname -a
Linux ubuntu1 3.11.0-15-generic #25~precise1-Ubuntu SMP Thu Jan 30 17:39:31 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
lantiancheng@ubuntu1:~/code$
uptime命令
uptime用于查看系统的负载信息,格式为uptime。
uptime命令真的很棒,它可以显示当前系统时间、系统已运行时间、启用终端数量以及平均负载值等信息。平均负载值指的是系统在最近1分钟、5分钟、15分钟内的压力情况(下面加粗的信息部分);负载值越低越好,尽量不要长期超过1,在生产环境中不要超过5。
lantiancheng@ubuntu1:~/code$ uptime
11:30:42 up 34 days, 45 min, 1 user, load average: 0.00, 0.01, 0.05
lantiancheng@ubuntu1:~/code$
free命令
free用于显示当前系统中内存的使用量信息,格式为“free [-h]”。
为了保证Linux系统不会因资源耗尽而突然宕机,运维人员需要时刻关注内存的使用量。在使用free命令时,可以结合使用-h参数以更人性化的方式输出当前内存的实时使用量信息。
lantiancheng@ubuntu1:~/code$ free -h
free: invalid option -- 'h'
usage: free [-b|-k|-m|-g] [-l] [-o] [-t] [-s delay] [-c count] [-V]
-b,-k,-m,-g show output in bytes, KB, MB, or GB
-l show detailed low and high memory statistics
-o use old format (no -/+buffers/cache line)
-t display total for RAM + swap
-s update every [delay] seconds
-c update [count] times
-V display version information and exit
lantiancheng@ubuntu1:~/code$ free -g
total used free shared buffers cached
Mem: 15 12 3 0 8 0
-/+ buffers/cache: 3 11
Swap: 15 0 15
lantiancheng@ubuntu1:~/code$
who命令
who用于查看当前登入主机的用户终端信息,格式为“who [参数]”。
lantiancheng@ubuntu1:~/code$ who
lantiancheng pts/2 2019-05-16 09:13 (172.16.1.232)
lantiancheng@ubuntu1:~/code$
history命令
history命令用于显示历史执行过的命令,格式为“history [-c]”。
history命令应该是作者最喜欢的命令。
执行history命令能显示出当前用户在本地计算机中执行过的最近1000条命令记录。如果觉得1000不够用,还可以自定义/etc/profile文件中的HISTSIZE变量值。在使用history命令时,如果使用-c参数则会清空所有的命令历史记录。还可以使用“!编码数字”的方式来重复执行某一次的命令。总之,history命令有很多有趣的玩法等待您去开发。