Bash的基础知识man手册

由于基于Android类设备的渗透测试都是通过各类终端实现。所以掌握Shell相关操作就显得尤为重要。Bash是一个为GNU计划编写的Unix Shell本文选自基于Android设备的Kali Linux渗透测试教程。

它是许多Linux平台内定Shell,还有许多传统UNIX上用的Shell,如tcsh、csh、ash、bsh、ksh等。Bash是大多数Linux系统上默认的Shell,本章将介绍Bash的基础知识。

2.1  man手册

Linux man中的man就是manual的缩写,中文说法是手册。在Linux中,man手册就是用来查看系统中自带的各种参考手册。通过查看man手册,可以从中获取到各种命令、文件、库函数等帮助信息。本节将介绍从man手册。

使用man文件是很容易的,这里首先介绍下它的语法格式及相关参数。man命令的语法格式如下所示:

  • man [SECTION NUMBER] MAN PAGE NAME

以上命令中,两个选项的含义如下所示:

q  SECTION NUMBER:表示man手册页的章节号。

q  MAN PAGE NAME:表示man手册名称,通常是命令、系统或库本身的名称。例如,如果查找man命令的手册页,执行命令如下所示:

  • man 1 man

在以上命令中,1表示告诉man命令为第1节,而man参数后面的命令就man手册页的名称。

Man手册页章节号是根据它们自己的规范定义的,主要分为几个部分。如下所示:

q  1:普通命令用这个段查找使用在命令行的命令信息。在上面这个命令中,使用它来查找关于man文件的信息。

q  2:系统调用:即由内核提供的函数。

q  3:C库函数。对于C语言开发,该文档是非常有用的,并且开发者使用开发语言作为C延伸工具,如Python。它将显示参数相关的信息,头文件的定义、行为和基本C库函数调用的目的。

q  4:特殊文件,也就是各种设备文件。这些文件通常保存在/dev/目录中,如字符设备、伪终端等。

q  5:文件格式和转化。该文档包含了Linux系统中文件的格式。如密码文件passwd,该手册页将会说明这个文件中各个字段的含义。

q  6:游戏和屏幕保护。该文档中包含关于游戏和屏幕保护程序信息。

q  7:杂集。该文档中包括各种命令信息和其它信息。

q  8:系统管理员命令和守护进程。该文档中命令和系统守护进程只能由管理员使用。

man手册的页面布局是标准化的,包含一个特定部分的集合。man手册页的每个部分都包含了描述、系统调用或库函数。下面分别介绍一下在man文件中目的相同的部分,如下所示:

q  Name:表示命令、函数、系统调用或文件格式的名称。

q  Synopsis:表示命令、函数、系统调用、文件格式等语法格式。

q  Description:对命令功能的描述

q  Examples:表示对命令如何使用给出的例子。

q  See also:表示参考文档、Web页面及与该程序有关的其它程序。

为了验证man手册的语法格式及内容格式等,下面举几个例子作为验证。

【实例2-1】查看本机伪终端的man手册页。执行命令如下所示:

  • android@localhost:~$ man 4 pts

执行以上命令后,将显示如下所示的信息:

  • PTS(4)                     Linux Programmer's Manual                    PTS(4)
  • NAME
  • ptmx, pts - pseudoterminal master and slave
  • DESCRIPTION
  • The  file  /dev/ptmx  is a character file with major number 5 and minor
  • number 2, usually of mode 0666 and owner.group  of  root.root.   It  is
  • used to create a pseudoterminal master and slave pair.
  • When  a  process opens /dev/ptmx, it gets a file descriptor for a pseu‐
  • doterminal master (PTM), and a pseudoterminal  slave  (PTS)  device  is
  • created  in  the  /dev/pts directory.  Each file descriptor obtained by
  • opening /dev/ptmx is an independent PTM with its  own  associated  PTS,
  • whose path can be found by passing the descriptor to ptsname(3).
  • Before  opening  the  pseudoterminal  slave, you must pass the master's
  • file descriptor to grantpt(3) and unlockpt(3).
  • Once both the pseudoterminal master and slave are open, the slave  pro‐
  • vides  processes  with an interface that is identical to that of a real
  • terminal.
  • ……
  • FILES
  • /dev/ptmx, /dev/pts/*
  • NOTES
  • The Linux support for the above (known as UNIX 98  pseudoterminal  nam‐
  • ing)  is  done  using the devpts file system, that should be mounted on
  • /dev/pts.
  • Before  this  UNIX  98  scheme,  master  pseudoterminals  were   called
  • /dev/ptyp0,  ...   and  slave  pseudoterminals /dev/ttyp0, ...  and one
  • needed lots of preallocated device nodes.
  • SEE ALSO
  • getpt(3), grantpt(3), ptsname(3), unlockpt(3), pty(7)
  • COLOPHON
  • This page is part of release 3.44 of the Linux  man-pages  project.   A
  • description  of  the project, and information about reporting bugs, can
  • be found at http://www.kernel.org/doc/man-pages/.

从以上输出的信息中,可以看到该手册页共有七部分,如主题、文件名称、文件保存位置、参考资料等。在输出信息的左上角可以看到显示了PTS(4)。其中,PTS表示手册名称,(4)表示手册位于第四章节。最后,按下q键退出man手册页本文选自基于Android设备的Kali Linux渗透测试教程。

【实例2-2】查看passwd文件的man手册页。执行命令如下所示:

  • android@localhost:~$ man 5 passwd

执行以上命令后,将输出如下所示的信息:

  • PASSWD(5)                File Formats and Conversions                PASSWD(5)
  • NAME
  • passwd - the password file
  • DESCRIPTION
  • /etc/passwd contains one line for each user account, with seven fields
  • delimited by colons (“:”). These fields are:
  • ·   login name
  • ·   optional encrypted password
  • ·   numerical user ID
  • ·   numerical group ID
  • ·   user name or comment field
  • ·   user home directory
  • ·   optional user command interpreter
  • The encrypted password field may be blank, in which case no password is
  • required to authenticate as the specified login name. However, some
  • applications which read the /etc/passwd file may decide not to permit
  • any access at all if the password field is blank. If the password field
  • is a lower-case “x”, then the encrypted password is actually stored in
  • the shadow(5) file instead; there must be a corresponding line in the
  • /etc/shadow file, or else the user account is invalid. If the password
  • field is any other string, then it will be treated as an encrypted
  • password, as specified by crypt(3).
  • The comment field is used by various system utilities, such as
  • finger(1).
  • The home directory field provides the name of the initial working
  • directory. The login program uses this information to set the value of
  • the $HOME environmental variable.
  • The command interpreter field provides the name of the user's command
  • language interpreter, or the name of the initial program to execute.
  • The login program uses this information to set the value of the $SHELL
  • environmental variable. If this field is empty, it defaults to the
  • value /bin/sh.
  • FILES
  • /etc/passwd
  • User account information.
  • /etc/shadow
  • optional encrypted password file
  • /etc/passwd-
  • Backup file for /etc/passwd.
  • Note that this file is used by the tools of the shadow toolsuite,
  • but not by all user and password management tools.
  • SEE ALSO
  • crypt(3), getent(1), getpwnam(3), login(1), passwd(1), pwck(8),
  • pwconv(8), pwunconv(8), shadow(5), su(1), sulogin(8).
  • shadow-utils 4.1.5.1              05/25/2012                         PASSWD(5)

从以上输出信息中,可以看到passwd文件中共有七个字段,并且每个字段使用“冒号:”分割。具体每个字段的作用,在该文档中都有详细介绍。在Linux系统中也有passwd命令,如果查看该命令的帮助信息,执行命令如下所示:

  • android@localhost:~$ man 1 passwd

输出信息如下所示:

  • PASSWD(1)                        User Commands                       PASSWD(1)
  • NAME
  • passwd - change user password
  • SYNOPSIS
  • passwd [options] [LOGIN]
  • DESCRIPTION
  • The passwd command changes passwords for user accounts. A normal user
  • may only change the password for his/her own account, while the
  • superuser may change the password for any account.  passwd also changes
  • the account or associated password validity period.
  • ……
  • OPTIONS
  • The options which apply to the passwd command are:
  • -a, --all
  • This option can be used only with -S and causes show status for all
  • users.
  • -d, --delete
  • Delete a user's password (make it empty). This is a quick way to
  • disable a password for an account. It will set the named account
  • passwordless.
  • -e, --expire
  • Immediately expire an account's password. This in effect can force
  • a user to change his/her password at the user's next login.
  • -h, --help
  • Display help message and exit.
  • -i, --inactive INACTIVE
  • This option is used to disable an account after the password has
  • been expired for a number of days. After a user account has had an
  • expired password for INACTIVE days, the user may no longer sign on
  • to the account.
  • ……
  • CAVEATS
  • Password complexity checking may vary from site to site. The user is
  • urged to select a password as complex as he or she feels comfortable
  • with.
  • Users may not be able to change their password on a system if NIS is
  • enabled and they are not logged into the NIS server.
  • passwd uses PAM to authenticate users and to change their passwords.
  • FILES
  • /etc/passwd
  • User account information.
  • /etc/shadow
  • Secure user account information.
  • /etc/pam.d/passwd
  • PAM configuration for passwd.
  • EXIT VALUES
  • The passwd command exits with the following values:
  • 0
  • success
  • 1
  • permission denied
  • 2
  • invalid combination of options
  • 3
  • unexpected failure, nothing done
  • 4
  • unexpected failure, passwd file missing
  • 5
  • passwd file busy, try again
  • 6
  • invalid argument to option
  • SEE ALSO
  • chpasswd(8), passwd(5), shadow(5), usermod(8).
  • shadow-utils 4.1.5.1              05/25/2012                         PASSWD(1)

在以上输出信息中,显示了passwd命令的语法格式、选项、描述等信息。从以上的输出信息中,可以发现使用的章节编号不同,显示的帮助文档内容也不同。在以上命令中,也可以不输入章节号1的。因为,man命令默认是从数字较小的手册中寻找相关命令和函数。

注意:man命令是按照手册的章节号顺序进行搜索的。例如查看sleep命令的手册,执行man sleep命令。如果想要查看库函数sleep,则需要执行man 3 sleep命令。这里的章节号,就必须输入本文选自基于Android设备的Kali Linux渗透测试教程。

Bash的基础知识man手册的更多相关文章

  1. Linux基础知识回顾及BASH学习

    2019-2020-030189224 <网络攻防技术与实践>第一周学习总结 Linux基础知识错题回顾 1.Linux中使用(B)命令新建空白文件. A .mkdir B .touch ...

  2. bash&nbsp;shell笔记1&nbsp;脚本基础知识

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://twentyfour.blog.51cto.com/945260/505644 * ...

  3. SWIG 3 中文手册——5. SWIG 基础知识

    目录 5 SWIG 基础知识 5.1 运行 SWIG 5.1.1 输入格式 5.1.2 SWIG 输出 5.1.3 注释 5.1.4 C 预处理器 5.1.5 SWIG 指令 5.1.6 解析限制 5 ...

  4. 系统和帮助-Linux基础知识

    iOS镜像: 硬盘分区:留出一些空间;实在不成,可安装完成以后,新增一块虚拟硬盘; 终端:terminal 用户界面: GUI:图形界面 GNome KDE CLI: bash,zsh,sh,csh, ...

  5. Linux Shell 基础知识(一)

    1. 本文知识结构 2. shell 基础知识 2.1 shell 简单介绍 ​ GNU bash shell 能提供对 Linux 系统的交互式访问,一般来说,使用快捷键 Ctrl + Alt + ...

  6. MySQL 基础知识梳理

    MySQL 的安装方式有多种,但是对于不同场景,会有最适合该场景的 MySQL 安装方式,下面就介绍一下 MySQL 常见的安装方法,包括 rpm 安装,yum 安装,通用二进制安装以及源码编译安装, ...

  7. 学习 shell脚本之前的基础知识

    转载自:http://www.92csz.com/study/linux/12.htm  学习 shell脚本之前的基础知识 日常的linux系统管理工作中必不可少的就是shell脚本,如果不会写sh ...

  8. Linux基础知识整理

    一.基础知识 1.Linux简介 Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户.多任务.支持多线程和多CPU的操作系统.它能运行主要的UNIX工具软件 ...

  9. java基础知识小总结【转】

    java基础知识小总结 在一个独立的原始程序里,只能有一个 public 类,却可以有许多 non-public 类.此外,若是在一个 Java 程序中没有一个类是 public,那么该 Java 程 ...

随机推荐

  1. 用firebug给firefox添加信任链接

    在前文“firefox查看微信公众平台的数据分析时就出现不信任链接怎么办?”我们使用了导入证书的方法添加信任链接,有网友反映说证书导入不成功,这里用另外一种方法来实现:用firebug给firefox ...

  2. Eclipse设置:背景与字体大小和xml文件中字体大小调整

    Eclipse中代码编辑背景颜色修改:代码编辑界面默认颜色为白色.对于长期使用电脑编程的人来说,白色很刺激我们的眼睛,所以改变workspace的背景色,可以使眼睛舒服一些.设置方法如下:1.打开wi ...

  3. ZeroMQ(java)之Router与Dealer运行原理

    在开始这部分的内容之前,先来看看ZeroMQ中HWM概念---High-Water Marks 当系统的数据量很大,而且发送频率很高的情况下,内存就很重要了,如果处理不好会出现很多问题,例如如下场景: ...

  4. HDU 1203 I NEED A OFFER (01背包&&概率dp)

    M - I NEED A OFFER! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  5. 以Python角度学习Javascript(一)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAO4AAADZCAIAAACo85tgAAAgAElEQVR4Aey9SdAs13XnV/P8jW8e8D ...

  6. 推荐一个linux下的web压力测试工具神器webbench

    推荐一个linux下的web压力测试工具神器webbench2014-04-30 09:35:29   来源:   评论:0 点击:880 用多了apache的ab工具之后你就会发现ab存在很多问题, ...

  7. http协议学习系列

    深入理解HTTP协议(转)  http://www.blogjava.net/zjusuyong/articles/304788.html http协议学习系列   1. 基础概念篇 1.1 介绍 H ...

  8. 72 [面试题]如果不使用if-else和比较运算符,你知道如何求解2个数字中的较大一个吗?

    [本文链接] http://www.cnblogs.com/hellogiser/p/max-of-numbers-without-comparations.html [题目] 不使用if-else和 ...

  9. GPU基本概念详解

    §1 个 multiprocessor <-> 1个instruction unit  <-> 8 个processor  <-> 在一个warp中执行  < ...

  10. 使用jquery制作可视化的组织结构

    组织结构是做项目里面经常用到的,但是要做成可视化的效果比较少,多数使用树结构来表示,但是对于客户来说不是太直观.可以用jOrgChart来实现.如下图的效果,这样就比较直观. 首先你要去下载jOrgC ...