0%

Linux基本命令

1.学会使用命令帮助

1.1.概述

在linux终端,面对命令不知道怎么用,或不记得命令的拼写及参数时,我们需要求助于系统的帮助文档; linux系统内置的帮助文档很详细,通常能解决我们的问题,我们需要掌握如何正确的去使用它们;

  • 在只记得部分命令关键字的场合,我们可通过man -k来搜索;
  • 需要知道某个命令的简要说明,可以使用whatis;而更详细的介绍,则可用info命令;
  • 查看命令在哪个位置,我们需要使用which;
  • 而对于命令的具体参数及使用方法,我们需要用到强大的man;

下面介绍这些命令;

1.2. 命令使用

查看命令的简要说明

简要说明命令的作用(显示命令所处的man分类页面):

1
$whatis command

正则匹配:

1
$whatis -w "loca*"

更加详细的说明文档:

1
$info command

使用man

查询命令command的说明文档:

1
2
$man command
eg:man date

使用page up和page down来上下翻页

在man的帮助手册中,将帮助文档分为了9个类别,对于有的关键字可能存在多个类别中, 我们就需要指定特定的类别来查看;(一般我们查询bash命令,归类在1类中);

man页面所属的分类标识(常用的是分类1和分类3)

1
2
3
4
5
6
7
8
9
(1)、用户可以操作的命令或者是可执行文件
(2)、系统核心可调用的函数与工具等
(3)、一些常用的函数与数据库
(4)、设备文件的说明
(5)、设置文件或者某些文件的格式
(6)、游戏
(7)、惯例与协议等。例如Linux标准文件系统、网络协议、ASCⅡ,码等说明内容
(8)、系统管理员可用的管理条令
(9)、与内核有关的文件

前面说到使用whatis会显示命令所在的具体的文档类别,我们学习如何使用它

1
2
3
4
5
6
7
eg:
$whatis printf
printf (1) - format and print data
printf (1p) - write formatted output
printf (3) - formatted output conversion
printf (3p) - print formatted output
printf [builtins] (1) - bash built-in commands, see bash(1)

我们看到printf在分类1和分类3中都有;分类1中的页面是命令操作及可执行文件的帮助;而3是常用函数库说明;如果我们想看的是C语言中printf的用法,可以指定查看分类3的帮助:

1
2
3
$man 3 printf

$man -k keyword

查询关键字 根据命令中部分关键字来查询命令,适用于只记住部分命令的场合;

eg:查找GNOME的config配置工具命令:

1
$man -k GNOME config| grep 1

对于某个单词搜索,可直接使用/word来使用: /-a

image-20220823193033900

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment