Bash的基礎知識man手冊
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
從以上輸出的資訊中,可以看到該手冊頁共有七部分,如主題、檔名稱、檔案儲存位置、參考資料等。在輸出資訊的左上角可以看到顯示了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滲透測試教程。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29597077/viewspace-1586613/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Linux的bash shell與man檢視手冊Linux
- MySQL基礎練習20題,看看你的sql基礎man不manMySql
- 基礎知識
- LUA的基礎知識
- 翻譯:man getopt(1)中文手冊
- React學習手記1--基礎知識React
- 手機APP UI設計尺寸基礎知識APPUI
- AI 基礎知識AI
- Webpack 基礎知識Web
- Dart基礎知識Dart
- RabbitMQ基礎知識MQ
- webpack基礎知識Web
- javascript基礎知識JavaScript
- ThinkPHP基礎知識PHP
- Laravel基礎知識Laravel
- Redis基礎知識Redis
- Docker基礎知識Docker
- 程式基礎知識
- Envoy基礎知識
- DockerFile基礎知識Docker
- Nginx基礎知識Nginx
- CSS基礎知識CSS
- Java基礎知識Java
- PRML 基礎知識
- BGP基礎知識
- PHP基礎知識PHP
- React基礎知識React
- httpclient基礎知識HTTPclient
- HBase基礎知識
- Jquery基礎知識jQuery
- js基礎知識JS
- PGA基礎知識
- Javascript 基礎知識JavaScript
- ASM基礎知識ASM
- html基礎知識HTML
- 黑客基礎知識黑客
- Mysqli基礎知識MySql
- oracle 基礎知識Oracle