命令的語法格式:
COMMAND OPTIONS ARGUMENTS
選項和參數都是能夠缺省的
命令組成:
系統自帶命令
應用程序
腳本文件linux
命令的類型:
內建命令: 由shell程序自帶的命令
查找方式:shell內建
外部命令: 自己是一個獨立的可執行程序文件,命令名即爲程序文件名
查找方式:經過shell的內置的環境變量PATH中指定的路徑進行查找; shell
如何區分:type COMMAND
[root@linux_basic ~]# type cd
cd is a shell builtin
[root@linux_basic ~]# type type
type is a shell builtin
[root@linux_basic ~]# which type
/usr/bin/which: no type in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root@linux_basic ~]# type type
type is a shell builtin
選項:調整命令的做用方式
短選項:-char, 例如,-l, -d, -h
多個選項間要使用空白分隔:-l -d -h
合併使用:-ldh
長選項:--word, 例如:--long, --directory, --human-readable
長選項通常不能合併使用數據庫
注意:有些選項須要帶參數,稱爲選項參數
mkfs -t ext4 bash
參數:
命令的做用對象app
cd: change directory
cd
cd ~
cd ~USERNAME
cd -: 在前一個目錄和當前目錄之間反覆切換ide
兩個獨特的路徑:
.: 當前目錄
..:上一級目錄ui
pwd: print working directorythis
命令歷史:bash的特性之一
history 顯示命令歷史
終止當前命令的執行:Ctrl+c
[root@linux_basic ~]# cd dlfjal^C
[root@linux_basic ~]#
保存的條數:
環境變量:HISTSIZEgoogle
用戶退出時的持久保存位置:
環境變量:HISTFILE,一般默認爲用戶家目錄下的.bash_history
[root@linux_basic ~]# echo $HISTFILE
/root/.bash_historyspa
此文件中可保存的最大數目:
環境變量:HISTFILESIZE
[root@linux_basic ~]# echo $HISTFILESIZE
1000
[root@linux_basic ~]# type history 全部的內建命令均可以經過help查看幫助
history is a shell builtin
用法:
history N: 顯示最近的N條使用過的命令,包括當前命令自身;
history -c: 清空全部的命令歷史
history -d offset: 刪除指定的偏移處的命令條目
history -a [/path/to/some_history_file]: 手動將當前會話中的命令歷史寫入指定文件
[ -w 寫入命令歷史文件中而且追加到命令歷史的列表中 ]
只有退出時,命令的歷史纔會自動保存到.bash_history文件中
bash調用命令歷史列表中的命令:
!#: 執行命令歷史中的第#條命令
!!: 執行上一條正確執行了的命令
!string: 執行命令歷史中最近一次以string開頭的命令;
!$: 調用上一條命令的最後一個參數
ESC, .:功能同上 按Esc鍵後加'.'號
如何獲取命令幫助:
內置命令:help COMMAND
例如:help history
外部命令:
一、COMMAND --help 絕大部分命令都是支持的,獲取命令簡要幫助信息
二、手冊:manual
手冊存放位置之一
[root@linux_basic init.d]# ls /usr/share/man/
bg da el es fr hu it ko man1 man1x man2x man3p man4 man5 man6 man7 man8 man9 mann overrides pt ro sk sv zh_CN
cs de en fi hr id ja man0p man1p man2 man3 man3x man4x man5x man6x man7x man8x man9x nl pl pt_BR ru sl tr zh_TW
[root@linux_basic init.d]#
i18n是internationalization的縮寫,意思指i和n之間有18個字母。/etc/sysconfig/i18n裏面存放着系統的區域語言
設置,可使linux系統支持國際化信息顯示。就是支持多種字符集的轉換,避免出現亂碼。同一時間i18n只能是英文
和一種選定的語言,例如英文+中文、英文+德文、英文+韓文等等。
[root@linux_basic init.d]# cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
Linux的國際化:
internationalization
# export LANG=en 手冊顯示有部分亂碼,設置一下環境變量
手冊:有章節之分,1-9
man [#] COMMAND 找到對應文件手冊並解壓顯示,默認沒寫章節時,顯示在whatis中的第一個出現的章節的
如何查看指定命令在哪些章節下有幫助:
whatis COMMAND
注意:whatis根據數據庫執行查找操做,此庫爲系統按期更新;可以使用makewhatis手動更新;
man查看手冊中各部分信息
手冊的段落:
NAME: 命令名稱
DESCRIPTION: 命令功能的詳細描述
OPTIONS: 全部選項
SYNOPSIS: 使用格式
EXAMPLES: 使用示例
FILES: 與當前命令相關的配置文件
SEE ALSO: 可參考的其它手冊
幫助中的格式字串:
[]:可省略
<>: 不可省略
|: 二選一或多選一,不能同時出現
...: 同類內容能夠出現多個
man的使用機制:
翻屏:
空格鍵:向文件尾部翻一屏
b: 向文件首部翻一屏
j,回車鍵:向文件尾部翻一行
k: 向文件首部翻一行
Ctrl+d: 向文件尾部翻半屏
Ctrl+u: 向文件首部翻並屏
字串搜索:
/keyword: 從文件首部向尾部進行搜索
?keyword: 從文件尾部向首部進行搜索
n: 顯示找到的下一個 顯示尋找字符在下一次出現的位置
N:顯示找到的上一個
退出:
q
注意:man可以爲除命令以外的配置文件、系統調用、庫調用等都能提供幫助手冊,它們分別位於不一樣的章節中; man man
1: 用戶命令
2: 系統調用
3: 庫調用
4: 設備文件
5: 配置文件
6: 遊戲
7:雜項
8:管理命令
經常使用的用8個
三、info命令:獲取在線文檔
僅在man手冊沒法獲取到足夠信息,或想了解程序的開發歷史時才使用info
四、不少應用程序都自帶有幫助文檔:/usr/share/doc/
ChangeLog: 程序版本升級的變更狀況
INSTALL: 安裝方法說明
README:程序說明信息
五、主流發行版官方文檔
redhat, suse, debian
RedHat: http://www.redhat.com/docs/
六、google
練習:獲取下面命令的使用方法
shutdown, date, hwclock, ntpdate, reboot, halt, who, whoami, which, hash
如何關機,如何重啓,如在指定時間上重啓
[root@linux_basic ~]# type shutdown
shutdown is /sbin/shutdown
[root@linux_basic ~]# shutdown --help
Usage: shutdown [OPTION]... TIME [MESSAGE]
Bring the system down.
Options:
-r reboot after shutdown 關機後從新啓動
-h halt or power off after shutdown 中止或關閉後關機
-H halt after shutdown (implies -h)
-P power off after shutdown (implies -h)
-c cancel a running shutdown
-k only send warnings, don't shutdown
-q, --quiet reduce output to errors only
-v, --verbose increase output to include informational messages
--help display this help and exit
--version output version information and exit
TIME may have different formats, the most common is simply the word 'now' which will bring the system down immediately. Other valid formats are +m, where m is
the number of minutes to wait until shutting down and hh:mm which specifies the time on the 24hr clock.
Logged in users are warned by a message sent to their terminal, you may include an optional MESSAGE included with this. Messages can be sent without actually
bringing the system down by using the -k option.
If TIME is given, the command will remain in the foreground until the shutdown occurs. It can be cancelled by Control-C, or by another user using the -c option.
The system is brought down into maintenance (single-user) mode by default, you can change this with either the -r or -h option which specify a reboot or system
halt respectively. The -h option can be further modified with -H or -P to specify whether to halt the system, or to power it off afterwards. The default is
left up to the shutdown scripts.
Report bugs at <https://launchpad.net/upstart/+bugs>
[root@linux_basic ~]# man shutdown
shutdown(8) shutdown(8)
NAME
shutdown - bring the system down
SYNOPSIS
shutdown [OPTION]... TIME [MESSAGE]
DESCRIPTION
shutdown arranges for the system to be brought down in a safe way. All logged-in users are notified that the system is going down and,
within the last five minutes of TIME, new logins are prevented.
TIME may have different formats, the most common is simply the word ’now’ which will bring the system down immediately. Other valid for-
mats are +m, where m is the number of minutes to wait until shutting down and hh:mm which specifies the time on the 24hr clock.
Once TIME has elapsed, shutdown sends a request to the init(8) daemon to bring the system down into the appropriate runlevel.
This is performed by emitting the runlevel(7) event, which includes the new runlevel in the RUNLEVEL environment variable as well as the
previous runlevel (obtained from the environment or from /var/run/utmp) in the PREVLEVEL variable. An additional INIT_HALT variable may
be set, this will contain the value HALT when bringing the system down for halt and POWEROFF when bringing the system down for power off.
OPTIONS
-r Requests that the system be rebooted after it has been brought down.
-h Requests that the system be either halted or powered off after it has been brought down, with the choice as to which left up to the
system.
-H Requests that the system be halted after it has been brought down.
-P Requests that the system be powered off after it has been brought down.
-c Cancels a running shutdown. TIME is not specified with this option, the first argument is MESSAGE.
-k Only send out the warning messages and disable logins, do not actually bring the system down.
ENVIRONMENT
RUNLEVEL
shutdown will read the current runlevel from this environment variable if set in preference to reading from /var/run/utmp
FILES
/var/run/utmp
Where the current runlevel will be read from; this file will also be updated with the new runlevel.
/var/log/wtmp
A new runlevel record will be appended to this file for the new runlevel.
NOTES
The Upstart init(8) daemon does not keep track of runlevels itself, instead they are implemented entirely by its userspace tools.
See runlevel(7) for more details.
AUTHOR
Written by Scott James Remnant <scott@netsplit.com>
REPORTING BUGS
Report bugs at <https://launchpad.net/upstart/+bugs>
COPYRIGHT
Copyright ? 2009 Canonical Ltd.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTIC-
ULAR PURPOSE.
SEE ALSO
runlevel(7) init(8) telinit(8) reboot(8)
shutdown -h
-r
-c
時間格式 shutdown -h now 馬上關機 now +m hh:mm