其他常用命令

返回主页

一、shutdown:关机

shutdown命令的功能是关闭Linux主机系统。

1、shutdown:语法格式

shutdown [参数] [对象]

2、shutdown:常用参数

参数 描述 参数 描述 参数 描述 参数 描述
-r 将系统立即重启 -h 将系统立即关机 -c 取消关机任务 -n 不调用init程序进行关机
-f 关机时不检查文件系统 -F 关机时先检查文件系统 -P 系统关机后切断电源 -s 关闭此计算机,非立即操作
-k 发送信息给所有用户 -t 设置距离关闭计算机还剩余的秒数

对象:使用now,now是一个特殊的时间关键字,意味着立刻、马上执行关机操作。

3、shutdown:参考事例

3.1、立刻关机

shutdown -h now

3.2、立刻重启

shutdown -r now

3.3、定时关机

# 下述指令表示在 23:00的时候执行关机操作。
shutdown -h 23:00

二、reboot:重启

reboot 指令的含义是重启计算机系统。shutdown -r now 指令也有类似的效果。

1、reboot:语法格式

reboot [参数]

2、reboot:常用参数

参数 描述 参数 描述 参数 描述
-d 不将重启系统的过程写入日志中 -f 强制重启系统而不询问 -i 关闭所有的网络服务然后再重启系统
-n 直接重启系统,不保存当前资料 -w 仅模拟重启过程,将过程写入日志中 --verbose 显示执行过程详细信息

3、reboot:参考事例

3.1、立刻重启

reboot

3.2、仅模拟重启过程,将过程写入日志中

reboot -w

三、clear/ctrl+L:清屏

clearctrl+L 命令都可以达到清空终端屏幕的效果。此命令使用频次很高。

四、hostname:显示和设置系统的主机名

hostname命令的功能是用于显示和设置当前系统的主机名,Linux系统中的HOSTNAME环境变量对应保存了当前的主机名称,使用hostname命令能够查看和设置此环境变量的值。

1、hostname:语法格式

hostname [参数] [主机名]

2、hostname:常用参数

参数 描述 参数 描述 参数 描述 参数 描述 参数 描述
-a 显示主机别名 -d 显示DNS域名 -f 显示FQDN名称 -F 从指定文件中读取主机名 -h 显示帮助信息
-i 显示主机IP地址 -s 显示短主机名 -v 显示执行过程详细信息 -V 显示版本信息 -y 显示NIS域名

3、hostname:参考事例

3.1、显示当前系统的主机名

[root@converts ~]# hostname
converts

# 也可以打印环境变量
[root@converts ~]# echo $HOSTNAME
converts

3.2、设置当前系统的主机名

# 设置当前系统的主机名
[root@VM-8-13-opencloudos ~] hostnamectl set-hostname converts

[root@converts ~]# hostname
converts

warning: hostnamectl set-hostname converts指令执行完毕之后立即生效。之所以看到的还是旧的主机名,是需要关闭终端之后才生效。

3.3、显示主机IP

[root@converts ~]# hostname -i
fe80::5054:ff:fe92:e1ed%eth0 fe80::42:11ff:feae:39c1%docker0 fe80::10a4:7aff:feff:8bcf%vethda489e7 10.0.8.13 172.17.0.1

五、history:显示命令历史

history命令的功能是显示与管理历史命令记录。Linux系统默认会记录用户执行过的有命令,可以使用history命令查阅它们,也可以对其记录进行修改和删除操作。

1、history:语法格式

history [参数]

2、history:常用参数

参数 描述 参数 描述 参数 描述 参数 描述
-a 保存命令记录 -r 读取命令记录到缓冲区 -c 清空命令记录 -s 添加命令记录到缓冲区
-d 删除指定序号的命令记录 -w 将缓冲区信息写入历史文件 -n 读取命令记录

3、history:参考事例

3.1、显示所有的历史命令记录

[root@converts ~]# history
    1   
    2  yum -y install gcc
    3  yum -y install gcc-c++
    4  yum install -y yum-utils
    5  yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    6  yum makecache fast
    7  yum install -y docker-ce docker-ce-cli containerd.io
    8  systemctl start docker
    9  systemctl enable docker.service
   10  systemctl enable containerd.service
.........................省略剩余部分..................................

3.2、显示最近执行的10条记录

[root@converts ~]# history 10
  303  touch converts.txt
  304  ll
  305  echo $HOSTNAME
  306  echo $HOSTNAMe
  307  hostname
  308  hostnamectl set-hostname converts
  309  hostname
  310  hostname -i
  311  history
  312  history 10

六、help:帮助命令

help 命令主要用来显示帮助信息,能够输出shell内部命令的帮助内容。由于Linux 的命令很多,并且相应的参数也很多,容易造成遗忘。这个时候就可以使用help进行查看,可以快速了解命令的各种用法。

1、help:语法格式

help [参数] [命令名]

2、help:常用参数

参数 描述 参数 描述 参数 描述
-d 显示命令的简短描述(注释) -s 显示短格式的帮助信息(指令列表) -m 使用man手册格式显示帮助信息

3、help:参考事例

3.1、查看指定命令的帮助信息

[root@converts ~]# help pwd
pwd: pwd [-LP]
    Print the name of the current working directory.

    Options:
      -L        print the value of $PWD if it names the current working
                directory
      -P        print the physical directory, without any symbolic links

    By default, `pwd' behaves as if `-L' were specified.

    Exit Status:
    Returns 0 unless an invalid option is given or the current directory
    cannot be read.
[root@converts ~]# man
What manual page do you want?
[root@converts ~]# help pwd
pwd: pwd [-LP]
    Print the name of the current working directory.

    Options:
      -L        print the value of $PWD if it names the current working
                directory
      -P        print the physical directory, without any symbolic links

    By default, `pwd' behaves as if `-L' were specified.

    Exit Status:
    Returns 0 unless an invalid option is given or the current directory
    cannot be read.

3.2、查看指定命令的帮助信息,以短语的形式输出

[root@converts ~]# help -s pwd
pwd: pwd [-LP]

可以看到输出的命令简洁了很多。

3.3、查看指定命令的帮助信息,只看该命令的注释、作用

[root@converts ~]# help -d pwd
pwd - Print the name of the current working directory.
展开/折叠菜单
123 预览数量 2024-03-28 09:43:26 发布 时间
目录
1 赞数量
评论数量
返回顶部
暂无评论

暂无评论