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. Button控件常用api

    加载按钮的纹理.loadTextures (const std::string &normal, const std::string &selected, const std::str ...

  2. Unity 利用NGUI做屏幕分辨率适配+学习UIDraggablePanel的使用

    原地址:http://blog.sina.com.cn/s/blog_697b1b8c0101g2r4.html 大家使用unity,一定有看中其跨平台的强大功能,因此也难免会遇到不同屏幕分辨率适配的 ...

  3. BZOJ 1452 [JSOI2009] Count

    这道题好像有点简单的样子... absi找题目好厉害啊...确实是一道比较裸的2dBIT啊. 水掉吧. 附:2dBIT怎么做: 2dBIT就是BIT套BIT啦. 所以修改loop(x+=lowbit( ...

  4. ECharts2.2.0 兼容IE8

    IE 8,ECharts2.2.0 版本,demo的各个功能均正常显示在IE8上面, 但是我在真正做的时候,我的html却不能显示,画面乱了,而且function也不能用, 都准备用1.4.1版本了, ...

  5. mysql varchar

    2013年9月13日 14:58:43 MYSQL的varchar数据类型 先说结论: 如果设置字段长度为30,字符编码为utf8,那么一个汉字算一个字符,一个数字算一个字符,一个字母也算一个字符 版 ...

  6. (转)SQL SERVER的锁机制(三)——概述(锁与事务隔离级别)

    五.锁与事务隔离级别 事务隔离级别简单的说,就是当激活事务时,控制事务内因SQL语句产生的锁定需要保留多入,影响范围多大,以防止多人访问时,在事务内发生数据查询的错误.设置事务隔离级别将影响整条连接. ...

  7. (转)SQL Server 中的事务和锁(三)-Range S-U,X-X 以及死锁

    在上一篇中忘记了一个细节.Range T-K 到底代表了什么?Range T-K Lock 代表了在 SERIALIZABLE 隔离级别中,为了保护范围内的数据不被并发的事务影响而使用的一类锁模式(避 ...

  8. Hadoop中操作HDFS出现异常的解决方法

    Hadoop环境搭建成功后,一般会运行一个小例子,这时候就涉及到了对HDFS文件系统的操作,对于刚开始学习Hadoop的初学者一般会多次的进行name节点的格式化操作,最后导致上传文件会抛出异常,通过 ...

  9. mysql生成varchar类型主键排序

    用uuid生成20位的主键 SELECT LEFT(REPLACE(UUID(), '-', ''),20) FROM DUAL 另一种方法: 因为数据库中有字母 需要排序的时候去除字母,重新取最大值 ...

  10. HDU1009老鼠的旅行 (贪心算法)

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...