168 lines
3.7 KiB
Markdown
168 lines
3.7 KiB
Markdown
|
---
|
|||
|
title: linux 常用命令-系统操作
|
|||
|
date: 2018/02/28
|
|||
|
categories:
|
|||
|
- linux
|
|||
|
tags:
|
|||
|
- linux
|
|||
|
- command
|
|||
|
---
|
|||
|
|
|||
|
<!-- TOC -->
|
|||
|
|
|||
|
- [linux 常用命令-系统操作](#linux-%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4-%E7%B3%BB%E7%BB%9F%E6%93%8D%E4%BD%9C)
|
|||
|
- [reboot](#reboot)
|
|||
|
- [补充说明](#%E8%A1%A5%E5%85%85%E8%AF%B4%E6%98%8E)
|
|||
|
- [语法](#%E8%AF%AD%E6%B3%95)
|
|||
|
- [选项](#%E9%80%89%E9%A1%B9)
|
|||
|
- [实例](#%E5%AE%9E%E4%BE%8B)
|
|||
|
- [exit](#exit)
|
|||
|
- [补充说明](#%E8%A1%A5%E5%85%85%E8%AF%B4%E6%98%8E)
|
|||
|
- [语法](#%E8%AF%AD%E6%B3%95)
|
|||
|
- [参数](#%E5%8F%82%E6%95%B0)
|
|||
|
- [实例](#%E5%AE%9E%E4%BE%8B)
|
|||
|
- [shutdown](#shutdown)
|
|||
|
- [补充说明](#%E8%A1%A5%E5%85%85%E8%AF%B4%E6%98%8E)
|
|||
|
- [语法](#%E8%AF%AD%E6%B3%95)
|
|||
|
- [选项](#%E9%80%89%E9%A1%B9)
|
|||
|
- [参数](#%E5%8F%82%E6%95%B0)
|
|||
|
- [实例](#%E5%AE%9E%E4%BE%8B)
|
|||
|
|
|||
|
<!-- /TOC -->
|
|||
|
|
|||
|
# linux 常用命令-系统操作
|
|||
|
|
|||
|
## reboot
|
|||
|
|
|||
|
重新启动正在运行的Linux操作系统
|
|||
|
|
|||
|
### 补充说明
|
|||
|
|
|||
|
**reboot命令** 用来重新启动正在运行的Linux操作系统。
|
|||
|
|
|||
|
### 语法
|
|||
|
|
|||
|
```
|
|||
|
reboot(选项)
|
|||
|
```
|
|||
|
|
|||
|
### 选项
|
|||
|
|
|||
|
```
|
|||
|
-d:重新开机时不把数据写入记录文件/var/tmp/wtmp。本参数具有“-n”参数效果;
|
|||
|
-f:强制重新开机,不调用shutdown指令的功能;
|
|||
|
-i:在重开机之前,先关闭所有网络界面;
|
|||
|
-n:重开机之前不检查是否有未结束的程序;
|
|||
|
-w:仅做测试,并不真正将系统重新开机,只会把重开机的数据写入/var/log目录下的wtmp记录文件。
|
|||
|
```
|
|||
|
|
|||
|
### 实例
|
|||
|
|
|||
|
```
|
|||
|
reboot //重开机。
|
|||
|
reboot -w //做个重开机的模拟(只有纪录并不会真的重开机)。
|
|||
|
```
|
|||
|
|
|||
|
## exit
|
|||
|
|
|||
|
退出当前的shell
|
|||
|
|
|||
|
### 补充说明
|
|||
|
|
|||
|
**exit命令** 同于退出shell,并返回给定值。在shell脚本中可以终止当前脚本执行。执行exit可使shell以指定的状态值退出。若不设置状态值参数,则shell以预设值退出。状态值0代表执行成功,其他值代表执行失败。
|
|||
|
|
|||
|
### 语法
|
|||
|
|
|||
|
```
|
|||
|
exit(参数)
|
|||
|
```
|
|||
|
|
|||
|
### 参数
|
|||
|
|
|||
|
返回值:指定shell返回值。
|
|||
|
|
|||
|
### 实例
|
|||
|
|
|||
|
退出当前shell:
|
|||
|
|
|||
|
```
|
|||
|
[root@localhost ~]# exit
|
|||
|
logout
|
|||
|
```
|
|||
|
|
|||
|
在脚本中,进入脚本所在目录,否则退出:
|
|||
|
|
|||
|
```
|
|||
|
cd $(dirname $0) || exit 1
|
|||
|
```
|
|||
|
|
|||
|
在脚本中,判断参数数量,不匹配就打印使用方式,退出:
|
|||
|
|
|||
|
```
|
|||
|
if [ "$#" -ne "2" ]; then
|
|||
|
echo "usage: $0 <area> <hours>"
|
|||
|
exit 2
|
|||
|
fi
|
|||
|
```
|
|||
|
|
|||
|
在脚本中,退出时删除临时文件:
|
|||
|
|
|||
|
```
|
|||
|
trap "rm -f tmpfile; echo Bye." EXIT
|
|||
|
```
|
|||
|
|
|||
|
检查上一命令的退出码:
|
|||
|
|
|||
|
```
|
|||
|
./mycommand.sh
|
|||
|
EXCODE=$?
|
|||
|
if [ "$EXCODE" == "0" ]; then
|
|||
|
echo "O.K"
|
|||
|
fi
|
|||
|
```
|
|||
|
|
|||
|
## shutdown
|
|||
|
|
|||
|
用来执行系统关机的命令。
|
|||
|
|
|||
|
### 补充说明
|
|||
|
|
|||
|
**shutdown命令** 用来系统关机命令。shutdown指令可以关闭所有程序,并依用户的需要,进行重新开机或关机的动作。
|
|||
|
|
|||
|
### 语法
|
|||
|
|
|||
|
```
|
|||
|
shutdown(选项)(参数)
|
|||
|
```
|
|||
|
|
|||
|
### 选项
|
|||
|
|
|||
|
```
|
|||
|
-c:当执行“shutdown -h 11:50”指令时,只要按+键就可以中断关机的指令;
|
|||
|
-f:重新启动时不执行fsck;
|
|||
|
-F:重新启动时执行fsck;
|
|||
|
-h:将系统关机;
|
|||
|
-k:只是送出信息给所有用户,但不会实际关机;
|
|||
|
-n:不调用init程序进行关机,而由shutdown自己进行;
|
|||
|
-r:shutdown之后重新启动;
|
|||
|
-t<秒数>:送出警告信息和删除信息之间要延迟多少秒。
|
|||
|
```
|
|||
|
|
|||
|
### 参数
|
|||
|
|
|||
|
* [时间]:设置多久时间后执行shutdown指令;
|
|||
|
* [警告信息]:要传送给所有登入用户的信息。
|
|||
|
|
|||
|
### 实例
|
|||
|
|
|||
|
指定现在立即关机:
|
|||
|
|
|||
|
```
|
|||
|
shutdown -h now
|
|||
|
```
|
|||
|
|
|||
|
指定5分钟后关机,同时送出警告信息给登入用户:
|
|||
|
|
|||
|
```
|
|||
|
shutdown +5 "System will shutdown after 5 minutes"
|
|||
|
```
|