linux基礎學習(1)

fufuh2o發表於2009-10-19

切換X WINDOWN 與命令列模式
 ctrl+alt+(F1-F6) 命令模式,default linux提供6個終端讓使用者登入(tty1-tty6)
 ctrl+alt+F7 切換到圖形介面
另外在命令模式  如果ctrl+alt+f7預設沒東西不是圖形介面
可以 執行startx

 

命令登入
[root@xhlinux ~]#
分析root表示username,root在linux就是supper user,xhlinux HOSTNAME
[root@xhlinux ~]# hostname
xhlinux
~:是一個變數 表示 使用者的主資料夾,例如root主資料夾 /root,~就=/root
另外在linux中 root default提示符為#,一般身份user提示符為$
[root@xhlinux ~]# exit
logout
  退出,登出(登入只是一個作業,登出時該作業停止,其他作業還可以執行)

 

 

linux命令執行:語法[root@xhlinux ~]# command [- option] parameter1 parameter2
分析:command :為命令名稱,例如cd,rm,ls等
[- option]: 加入引數時設定 一般 為 -號 ,比如-h,完整的引數名稱輸入--符號,例如--help
parameter 1..2:是在-options或command後面的引數
command [- option] parameter1:中間以空格區分,不論中間幾個空格,shell都視作一格(簡單說shell為linux提供給user一些工具,可以控制核心動作)
[root@xhlinux ~]# ls -al /root
total 332
drwxr-x---  15 root root  4096 Oct 19 21:09 .
drwxr-xr-x  23 root root  4096 Oct 19 20:58 ..
-rw-r--r--   1 root root  1173 Aug 16 23:40 anaconda-ks.cfg
..........................................
[root@xhlinux ~]# ls -al      /root
total 332
drwxr-x---  15 root root  4096 Oct 19 21:09 .
drwxr-xr-x  23 root root  4096 Oct 19 20:58 ..
-rw-r--r--   1 root root  1173 Aug 16 23:40 anaconda-ks.cfg
-
.....................................
可以看到linux視為一個空格


但大小寫 卻不一樣
[root@xhlinux ~]# date
Mon Oct 19 21:35:12 CST 2009
[root@xhlinux ~]# DATA
-bash: DATA: command not found
[root@xhlinux ~]#
比如VTEST與vtest在linux中是2個 完全不一樣的 檔案

 

 

基本命令:
[root@xhlinux ~]# date
Mon Oct 19 21:36:19 CST 2009 
檢視當前時間

加上一些引數
[root@xhlinux ~]# date +%y/%m/%d
09/10/19

[root@xhlinux ~]# date +%H:%M
21:37
[root@xhlinux ~]# date +%h:%m
Oct:10
可以 看到引數大小寫是完全不同的 2個命令

[root@xhlinux ~]# cal  顯示 日曆
    October 2009
Su Mo Tu We Th Fr Sa
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

[root@xhlinux ~]# cal 2009
                               2009                               

       January               February                 March       
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
             1  2  3    1  2  3  4  5  6  7    1  2  3  4  5  6  7
 4  5  6  7  8  9 10    8  9 10 11 12 13 14    8  9 10 11 12 13 14
11 12 13 14 15 16 17   15 16 17 18 19 20 21   15 16 17 18 19 20 21
18 19 20 21 22 23 24   22 23 24 25 26 27 28   22 23 24 25 26 27 28
25 26 27 28 29 30 31                          29 30 31

        April                   May                   June        
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
          1  2  3  4                   1  2       1  2  3  4  5  6
 5  6  7  8  9 10 11    3  4  5  6  7  8  9    7  8  9 10 11 12 13
12 13 14 15 16 17 18   10 11 12 13 14 15 16   14 15 16 17 18 19 20
19 20 21 22 23 24 25   17 18 19 20 21 22 23   21 22 23 24 25 26 27
26 27 28 29 30         24 25 26 27 28 29 30   28 29 30
                       31
        July                  August                September     
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
          1  2  3  4                      1          1  2  3  4  5
 5  6  7  8  9 10 11    2  3  4  5  6  7  8    6  7  8  9 10 11 12
12 13 14 15 16 17 18    9 10 11 12 13 14 15   13 14 15 16 17 18 19
19 20 21 22 23 24 25   16 17 18 19 20 21 22   20 21 22 23 24 25 26
26 27 28 29 30 31      23 24 25 26 27 28 29   27 28 29 30
                       30 31
       October               November               December      
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
             1  2  3    1  2  3  4  5  6  7          1  2  3  4  5
 4  5  6  7  8  9 10    8  9 10 11 12 13 14    6  7  8  9 10 11 12
11 12 13 14 15 16 17   15 16 17 18 19 20 21   13 14 15 16 17 18 19
18 19 20 21 22 23 24   22 23 24 25 26 27 28   20 21 22 23 24 25 26
25 26 27 28 29 30 31   29 30                  27 28 29 30 31


[root@xhlinux ~]# cal 9 2009
   September 2009
Su Mo Tu We Th Fr Sa
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
可以看到cal命令語法 為cal month year


計算器:BC
[root@xhlinux ~]# bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.


1+2
3
1*100
100
10/100~~~~~10/100應該為0.1而卻輸出了0,因為bc計算器default輸出整數,要輸出小數點後的 需要scale=number(小數點後幾位)
0

scale=3
10/100
.100

quit~~~~~~~~~~~~~退出
[root@xhlinux ~]#

重要的 熱鍵:
TAB:具有命令補全,檔案補全的功能

[root@xhlinux ~]# ca(ca後按2次tab 列出所有ca開頭的命令)
cacertdir_rehash    callgrind_control   card
cadaver             cancel              cardctl
cal                 cancel.cups         cardmgr
calibrate_ppa       capifax             case
callback            capifaxrcvd         cat
caller              capiinfo            catchsegv
callgrind           capiinit           
callgrind_annotate  captoinfo 


[root@xhlinux ~]# ls -al ~/.bash
ls: /root/.bash: No such file or directory

[root@xhlinux ~]# ls -al ~/.bash(2次tab)
.bash_history  .bash_logout   .bash_profile  .bashrc 
     
所有以.bash的檔名都會顯示出來   ,如果按tab在命令後(例如:ca 後)那麼為命令補全,如果在第2個字以後 (例中 在.bash後)表示檔案補齊
    
ctrl+c:中斷當前操作 立刻終止

ctrl_d:表示輸出結束,等於輸入exit
[root@xhlinux ~]# bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~按ctrl+d
[root@xhlinux ~]# ~~~~~~~~~~~~退出


錯誤資訊:
[root@xhlinux ~]# DATE
-bash: DATE: command not found
[root@xhlinux ~]# cal 13 2009
cal: illegal month value: use 1-12
linux的錯誤資訊寫的 非常 直觀 可以 直接看

 

關於linux的 所有命令
[root@xhlinux ~]#  按2次tab
[root@xhlinux ~]#
Display all 2684 possibilities? (y or n) 是否顯示 2684個 命令
c2ph
c89
c99
cacertdir_rehash
cadaver
cal
calibrate_ppa
callback
caller
callgrind
callgrind_annotate
callgrind_control
cancel
cancel.cups
capifax
capifaxrcvd
capiinfo
capiinit
captoinfo
--More--
captoinfo
[root@xhlinux ~]# 可以看 到有很多 ctrl+c 立即終止操作,只看下大概就可以

2684個命令如何記憶使用:
檢視幫助檔案 linux提供:man page/info page

[[root@xhlinux ~]# man date
DATE(1)                         User Commands                         DATE(1)

NAME
       date - print or set the system date and time

SYNOPSIS
       date [OPTION]... [+FORMAT]
       date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

DESCRIPTION
       Display  the current time in the given FORMAT, or set the system date.

       -d, --date=STRING
              display time described by STRING, not 'now'

       -f, --file=DATEFILE
              like --date once for each line of DATEFILE

       -ITIMESPEC, --iso-8601[=TIMESPEC]
              output date/time in ISO 8601 format.  TIMESPEC='date' for  date
              only, 'hours', 'minutes', or 'seconds' for date and time to the
              indicated precision.  --iso-8601 without TIMESPEC  defaults  to
              'date'.

       -r, --reference=FILE
              display the last modification time of FILE

       -R, --rfc-2822
              output RFC-2822 compliant date string

       -s, --set=STRING
              set time described by STRING

       -u, --utc, --universal
              print or set Coordinated Universal Time

       --help display this help and exit

       --version
              output version information and exit

       FORMAT controls the output.  The only valid option for the second form
       specifies Coordinated Universal Time.  Interpreted sequences are:

       %%     a literal %

       %a     locale's abbreviated weekday name (Sun..Sat)

       %A     locale's full weekday name, variable length (Sunday..Saturday)

       %b     locale's abbreviated month name (Jan..Dec)

       %B     locale's full month name, variable length (January..December)

       %c     locale's date and time (Sat Nov 04 12:02:33 EST 1989)

       %C     century (year divided by  100  and  truncated  to  an  integer)
              [00-99]

       %d     day of month (01..31)

       %D     date (mm/dd/yy)

       %e     day of month, blank padded ( 1..31)

       %F     same as %Y-%m-%d

       %g     the 2-digit year corresponding to the %V week number

       %G     the 4-digit year corresponding to the %V week number

       %h     same as %b

       %H     hour (00..23)

       %I     hour (01..12)

       %j     day of year (001..366)

       %k     hour ( 0..23)

       %l     hour ( 1..12)

       %m     month (01..12)

       %M     minute (00..59)

       %n     a newline

       %N     nanoseconds (000000000..999999999)

       %p     locale's upper case AM or PM indicator (blank in many locales)

       %P     locale's lower case am or pm indicator (blank in many locales)

       %r     time, 12-hour (hh:mm:ss [AP]M)

       %R     time, 24-hour (hh:mm)

       %s     seconds since '00:00:00 1970-01-01 UTC' (a GNU extension)

       %S     second (00..60); the 60 is necessary to accommodate a leap sec-
              ond

       %t     a horizontal tab

       %T     time, 24-hour (hh:mm:ss)

       %u     day of week (1..7);  1 represents Monday

       %U     week number of year with Sunday as first day of week (00..53)

       %V     week number of year with Monday as first day of week (01..53)

       %w     day of week (0..6);  0 represents Sunday

       %W     week number of year with Monday as first day of week (00..53)

       %x     locale's date representation (mm/dd/yy)

       %X     locale's time representation (%H:%M:%S)

       %y     last two digits of year (00..99)

       %Y     year (1970...)

       %z     RFC-2822 style. numeric timezone (-0500) (a  nonstandard  exten-
              sion)

       %Z     time  zone  (e.g.,  EDT),  or nothing if no time zone is deter-
              minable

       By default, date pads numeric fields with zeroes.  GNU date recognizes
       the following modifiers between '%' and a numeric directive.

              '-'  (hyphen)  do  not  pad  the field '_' (underscore) pad the
              field with spaces

ENVIRONMENT
       TZ     Specifies the  timezone,  unless  overridden  by  command  line
              parameters.    If   neither  is  specified,  the  setting  from
              /etc/localtime is used.

AUTHOR
       Written by David MacKenzie.

REPORTING BUGS
       Report bugs to <bug-coreutils@gnu.org>.

COPYRIGHT
       Copyright (C) 2004 Free Software Foundation, Inc.
       This is free software; see the source for copying  conditions.   There
       is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU-
       LAR PURPOSE.

SEE ALSO
       The full documentation for date is maintained as a Texinfo manual.  If
       the  info  and  date programs are properly installed at your site, the
       command

              info coreutils date

       should give you access to the complete manual.

date (coreutils) 5.2.1            March 2004                          DATE(1)
(END)

可以看到 date命令的 完整使用介紹


 [root@xhlinux ~]#  按q 退出 結束rman page
PAGE DOWN &空格 下一頁,page up上一頁,home 第一頁,end最後一頁
/ 字串 向下搜尋 ,?字串 向上搜尋  例如(搜尋 XH /xh,or ?xh, )
n,N 使用 ?/搜尋字元時搭配使用 n繼續向下查詢,N往上查詢 ,比如?xh 向上查xh字元 然後按N 那麼繼續向上查xh字元

man page 的資料一般存在/usr/share/man目錄

[root@xhlinux ~]# ls -al /usr/share/man
total 600
drwxr-xr-x   39 root root   4096 Aug 16 23:21 .
drwxr-xr-x  207 root root   4096 Aug 16 23:39 ..
drwxr-xr-x    4 root root   4096 Nov 17  2007 bg
drwxr-xr-x    4 root root   4096 Nov 17  2007 cs
drwxr-xr-x    4 root root   4096 Nov 17  2007 da
drwxr-xr-x    5 root root   4096 Nov 17  2007 de
drwxr-xr-x    5 root root   4096 Nov 17  2007 el
drwxr-xr-x    9 root root   4096 Nov 17  2007 en
drwxr-xr-x    4 root root   4096 Nov 17  2007 es
drwxr-xr-x    4 root root   4096 Nov 17  2007 fi
drwxr-xr-x    5 root root   4096 Nov 17  2007 fr
drwxr-xr-x    4 root root   4096 Nov 17  2007 hr
drwxr-xr-x    3 root root   4096 Aug 16 23:20 hu
drwxr-xr-x    3 root root   4096 Aug 16 23:20 id
drwxr-xr-x    5 root root   4096 Nov 17  2007 it
drwxr-xr-x    5 root root   4096 Nov 17  2007 ja
drwxr-xr-x    4 root root   4096 Nov 17  2007 ko
drwxr-xr-x    2 root root   4096 Aug 16 23:21 man0p
drwxr-xr-x    2 root root  53248 Aug 16 23:38 man1
drwxr-xr-x    2 root root   4096 Aug 16 23:21 man1p
drwxr-xr-x    2 root root  16384 Aug 16 23:33 man2
drwxr-xr-x    2 root root 167936 Aug 16 23:38 man3
drwxr-xr-x    2 root root  40960 Aug 16 23:21 man3p
drwxr-xr-x    2 root root   4096 Aug 16 23:29 man4
drwxr-xr-x    2 root root  12288 Aug 16 23:38 man5
drwxr-xr-x    2 root root   4096 Aug 16 23:21 man6
drwxr-xr-x    2 root root   4096 Aug 16 23:38 man7
drwxr-xr-x    2 root root  20480 Aug 16 23:38 man8
drwxr-xr-x    2 root root   4096 Feb 22  2005 man9
drwxr-xr-x    2 root root   4096 Feb 22  2005 mann
drwxr-xr-x    4 root root   4096 Nov 17  2007 nl
drwxr-xr-x    5 root root   4096 Nov 17  2007 pl
drwxr-xr-x    5 root root   4096 Nov 17  2007 pt
drwxr-xr-x    5 root root   4096 Aug 16 23:20 pt_BR
drwxr-xr-x    5 root root   4096 Nov 17  2007 ro
drwxr-xr-x    3 root root   4096 Aug 16 23:20 ru
drwxr-xr-x    3 root root   4096 Aug 16 23:20 sk
drwxr-xr-x    4 root root   4096 Nov 17  2007 sl
drwxr-xr-x    3 root root   4096 Aug 16 23:21 sv

可以修改man page搜尋路徑來改變這個目錄,修改/etc/man.config(man.conf,manpath.conf 不同版本)
[root@xhlinux ~]# ls -al /etc/man.config
-rw-r--r--  1 root root 4522 Nov 17  2007 /etc/man.config


[root@xhlinux ~]# man man (檢視man的 更多 使用 方法)
man: No such file or directory
Failed to open the message catalog man on the path NLSPATH=

Formatting page, please wait...
man(1)                                                                 man(1)

NAME
       man - format and display the on-line manual pages

SYNOPSIS
       man  [-acdfFhkKtwW]  [--path] [-m system] [-p string] [-C config_file]
       [-M pathlist] [-P pager] [-S section_list] [section] name ...

DESCRIPTION
       man formats and displays the on-line manual  pages.   If  you  specify
       section,  man  only looks in that section of the manual.  name is nor-
       mally the name of the manual page, which is typically the  name  of  a
       command,  function,  or  file.   However, if name contains a slash (/)
       then man interprets it as a file specification, so that you can do man
       ./foo.5 or even man /cd/foo/bar.1.gz.

       See  below  for  a  description of where man looks for the manual page
       files.

OPTIONS
       -C  config_file
              Specify  the  configuration  file  to  use;  the   default   is
              /etc/man.config.  (See man.config(5).)

       -M  path
              Specify the list of directories to search for man pages.  Sepa-
              rate the directories with colons.  An empty list is the same as
              not specifying -M at all.  See SEARCH PATH FOR MANUAL PAGES.

       -P  pager
              Specify which pager to use.  This option overrides the MANPAGER
              environment variable, which in turn overrides the  PAGER  vari-
              able.  By default, man uses /usr/bin/less -iRs.

       -S  section_list
              List  is  a  colon separated list of manual sections to search.
              This option overrides the MANSECT environment variable.

       -a     By default, man will exit after  displaying  the  first  manual
              page it finds.  Using this option forces man to display all the
              manual pages that match name, not just the first.

       -b     Disable any reference to color in the roff source.  NOCOLOR  in
............................................................................ -

       -f     Equivalent to whatis.

       -F or --preformat
             Format only - do not display.
...................................................................

 

 


info page與 man page類似 存/usr/share/info

root@xhlinux ~]# ls -al /usr/share/info
total 10804
drwxr-xr-x    2 root root  12288 Aug 16 23:38 .
drwxr-xr-x  207 root root   4096 Aug 16 23:39 ..
-rw-r--r--    1 root root  82802 May  3  2007 a2ps.info.gz
-rw-r--r--    1 root root  10441 Jan 18  2007 accounting.info.gz
-rw-r--r--    1 root root  15328 Aug 13  2006 ada-mode.gz
-rw-r--r--    1 root root  14200 Jul 26  2008 annotate.info.gz
-rw-r--r--    1 root root 178879 Jul 26  2008 as.info.gz
....................................
[root@xhlinux ~]# info info ~~~~~~~~~~~~檢視info 幫助檔案

File: info.info,  Node: Help-Small-Screen,  Next: Help,  Up: Getting Started

1.1 Starting Info on a Small Screen
===================================

Since your terminal has a relatively small number of lines on its
screen, it is necessary to give you special advice at the beginning.

   If you see the text `--All----' near the bottom right corner of the
screen, it means the entire text you are looking at fits on the screen.
If you see `--Top----' instead, it means that there is more text below
that does not fit.  To move forward through the text and see another
screen full, press , the Space bar.  To move back up, press the
key labeled `Backspace' or `DEL' (on some keyboards, this key might be
labeled `Delete').

   Here are 40 lines of junk, so you can try and and see
what they do.  At the end are instructions of what you should do next.


基本檢視時操作:空格 向下翻一頁,pagedown 向下翻一頁,pageup向上 翻一頁, tab在node間移動 (NODE地方通常顯示為*)
回車 當游標在node 上時 回車 可以進入該node
b:移動游標到當前info畫面中第一個node 處
e:移動游標到當前info畫面中最後一個node處
n:前往下一個info page 處
p:前往上一個info page處
u:向上移動一層
s or (/):在info page中搜尋
h:顯示幫助選單
?:命令一覽表
q:結束關閉info page

Search for string [at]:   按/ 搜尋at

?命令一覽
Basic Commands in Info Windows
******************************

l           Quit this help.
C-x C-c     Quit Info altogether.
h           Invoke the Info tutorial.

Selecting other nodes:
----------------------
n           Move to the "next" node of this node.
p           Move to the "previous" node of this node.
u           Move "up" from this node.
m           Pick menu item specified by name.
              Picking a menu item causes another node to be selected.
r           Follow a cross reference.  Reads name of reference.
l           Move to the last node seen in this window.
TAB         Skip to next hypertext link within this node.
M-TAB       Skip to previous hypertext link within this node.
RET         Follow the hypertext link under cursor.
d           Move to the `directory' node.  Equivalent to `g (DIR)'.
t           Move to the Top node.  Equivalent to `g Top'.

--zz-Info: (info.info.gz)Top, 24 lines --Top------------------------------------
[root@xhlinux ~]# info info


This is line 21~~~~~~~~~~~H(顯示幫助選單)
This is line 22
This is line 23
This is line 24
This is line 25
This is line 26
This is line 27
This is line 28
This is line 29
This is line 30
This is line 31
This is line 32

--zz-Info: (info.info.gz)Help-Small-Screen, 66 lines --Top----------------------

如果想知道bash是什麼 可以 訪問 usr/share/doc/bash-3.0裡面有 很多資訊 可以 參考學習
[root@xhlinux ~]# ls -al /usr/share/doc/bash-3.0
total 3776
drwxr-xr-x   11 root root   4096 Aug 16 23:19 .
drwxr-xr-x  466 root root  20480 Aug 16 23:39 ..
-rw-r--r--    1 root root 186787 Jul 17  2004 CHANGES
-rw-r--r--    1 root root   8398 Jul 17  2004 COMPAT
-rw-r--r--    1 root root  70974 Jul 22  2004 FAQ
-rw-r--r--    1 root root   7072 Feb 18  1999 INTRO
-rw-r--r--    1 root root  45847 Jul  3  2004 NEWS
-rw-r--r--    1 root root  13210 Oct 14  2003 NOTES
-rw-r--r--    1 root root   6539 Jul 27  2004 POSIX
-rw-r--r--    1 root root  41762 Oct 20  1994 article.ms
-rw-r--r--    1 root root  81474 Nov 20  2001 article.ps
-rw-r--r--    1 root root  48004 Oct 29  1994 article.txt
-rw-r--r--    1 root root 321470 Jul 12  2004 bash.0

 


linux關機

[root@xhlinux ~]# sync 磁碟同步,linux系統中為了加快資料讀取速度,default下某些資料不會直接寫入disk,而是先存記憶體中 ,可以手動執行SYNC 將資料寫入disk
避免不正常情況下 資料 未寫入disk
shutdown,reboot,halt 命令在關機前,自動進行了  SYNC 呼叫

常用的關機命令:

[root@xhlinux ~]# man shutdown  先看下 如何使用
man: No such file or directory
Failed to open the message catalog man on the path NLSPATH=

Formatting page, please wait...
SHUTDOWN(8)          Linux System Administrator's Manual          SHUTDOWN(8)

NAME
       shutdown - bring the system down

SYNOPSIS
       /sbin/shutdown [-t sec] [-arkhncfF] time [warning-message]

DESCRIPTION
       shutdown  brings the system down in a secure way.  All logged-in users
       are notified that the system is going down, and login(1)  is  blocked.
       It  is  possible to shut the system down immediately or after a speci-
       fied delay.  All processes are first notified that the system is going
       down  by  the signal SIGTERM.  This gives programs like vi(1) the time
       to save the file being edited, mail and  news  processing  programs  a
       chance  to exit cleanly, etc.  shutdown does its job by signalling the
       init process, asking it to change the runlevel.  Runlevel 0 is used to
       halt the system, runlevel 6 is used to reboot the system, and runlevel
       1 is used to put to system into a state where administrative tasks can
       be  performed;  this  is  the  default if neither the -h or -r flag is
       given to shutdown.  To see which actions are taken on halt  or  reboot
       see the appropriate entries for these runlevels in the file /etc/init-
       tab.

OPTIONS
       -a     Use /etc/shutdown.allow.

       -t sec Tell init(8) to wait sec seconds between sending processes  the
              warning  and  the  kill signal, before changing to another run-
              level.

       -k     Don't really shutdown; only send the warning messages to every-
              body.

       -r     Reboot after shutdown.

       -h     Halt after shutdown.

       -n     [DEPRECATED]  Don't  call  init(8) to do the shutdown but do it
              ourself.  The use  of  this  option  is  discouraged,  and  its
              results are not always what you'd expect.

       -f     Skip fsck on reboot.

       -F     Force fsck on reboot.

       -c     Cancel  an  already running shutdown. With this option it is of
              course not possible to give the  time  argument,  but  you  can
              enter  a  explanatory  message on the command line that will be
              sent to all users.

       time   When to shutdown.

       warning-message
              Message to send to all users.

       The time argument can have different formats.  First,  it  can  be  an
       absolute  time  in  the  format hh:mm, in which hh is the hour (1 or 2
       digits) and mm is the minute of the hour (in two digits).  Second,  it
       can  be in the format +m, in which m is the number of minutes to wait.
       The word now is an alias for +0.

       If shutdown is called with a  delay,  it  creates  the  advisory  file
       /etc/nologin  which  causes programs such as login(1) to not allow new
       user logins. Shutdown removes this file if it is stopped before it can
       signal  init  (i.e. it is cancelled or something goes wrong).  It also
       removes it before calling init to change the runlevel.

       The -f flag means 'reboot fast'.  This only creates an  advisory  file
       /fastboot  which  can  be tested by the system when it comes up again.
       The boot rc file can test if this file is present, and decide  not  to
       run  fsck(1)  since  the  system has been shut down in the proper way.
       After that, the boot process should remove /fastboot.

       The -F flag means 'force fsck'.  This only creates  an  advisory  file
       /forcefsck  which  can be tested by the system when it comes up again.
       The boot rc file can test if this file is present, and decide  to  run
       fsck(1)  with  a  special 'force' flag so that even properly unmounted
       filesystems get checked.  After that, the boot process  should  remove
       /forcefsck.

       The  -n flag causes shutdown not to call init, but to kill all running
       processes itself.  shutdown will then turn off quota, accounting,  and
       swapping and unmount all filesystems.

ACCESS CONTROL
       shutdown  can  be called from init(8) when the magic keys CTRL-ALT-DEL
       are pressed, by creating an appropriate entry  in  /etc/inittab.  This
       means  that  everyone  who has physical access to the console keyboard
       can shut the system down. To prevent this, shutdown can check  to  see
       if  an authorized user is logged in on one of the virtual consoles. If
       shutdown is called with the -a argument (add this to the invocation of
       shutdown  in  /etc/inittab),  it  checks to see if the file /etc/shut-
       down.allow is present.  It then compares the login names in that  file
       with  the list of people that are logged in on a virtual console (from
       /var/run/utmp). Only if one of  those  authorized  users  or  root  is
       logged in, it will proceed. Otherwise it will write the message

       shutdown: no authorized users logged in

       to the (physical) system console. The format of /etc/shutdown.allow is
       one user name per line. Empty lines and comment lines (prefixed  by  a
       #) are allowed. Currently there is a limit of 32 users in this file.

       Note  that  if  /etc/shutdown.allow is not present, the -a argument is
       ignored.

FILES
       /fastboot
       /etc/inittab
       /etc/init.d/halt
       /etc/init.d/reboot
       /etc/shutdown.allow

NOTES
       A lot of users forget to give the time argument and are  then  puzzled
       by  the  error  message shutdown produces. The time argument is manda-
       tory; in 90 percent of all cases this argument will be the word now.

       Init can only capture CTRL-ALT-DEL and start shutdown in console mode.
       If  the  system is running the X window System, the X server processes
       all key strokes. Some X11 environments make  it  possible  to  capture
       CTRL-ALT-DEL, but what exactly is done with that event depends on that
       environment.

       Shutdown wasn't designed to be run setuid. /etc/shutdown.allow is  not
       used to find out who is executing shutdown, it ONLY checks who is cur-
       rently logged in on (one of the) console(s).

AUTHOR
       Miquel van Smoorenburg, miquels@cistron.nl

SEE ALSO
       fsck(8), init(8), halt(8), poweroff(8), reboot(8)

-t sec:-t後加秒數,幾秒後關機
-k:不真關機,只發警告
-r:系統服務停掉後重啟機器
-h:系統服務停掉後 關機
-n:不經過init 程式,直接shutdown關機
-f:關機並啟動後,強制略過 fsck的磁碟檢查
-F:系統重啟後,強制 FSCk 的磁碟檢查
-c:取消 正在程式的 shutdown 命令

[root@xhlinux ~]# shutdown -k now 'this is shutdown test'

Broadcast message from root (pts/1) (Mon Oct 19 22:32:20 2009):

this is shutdown test
The system is going down to maintenance mode NOW!

Shutdown cancelled.
立即發出一個警告,但不關機


Shutdown cancelled.
[root@xhlinux ~]# shutdown -h +5~~~~5分鐘後 關機 (-h 24:00 ,-h now 馬上關機,-h now '可加警告') 24點關機

Broadcast message from root (pts/1) (Mon Oct 19 22:32:58 2009):

The system is going DOWN for system halt in 5 minutes!


[root@xhlinux ~]# shutdown -r now 立即重新啟動 (-r +30 'ssssss' 30分鐘後重新 啟動 加警告)

Broadcast message from root (pts/1) (Mon Oct 19 22:34:28 2009):

The system is going down for reboot NOW!
[root@xhlinux ~]#


另外這些後面都可以跟警告

重啟
reboot,halt,poweroff,3個命令基本一樣

reboot與 shutdown -r now一樣


[root@xhlinux ~]# halt

Broadcast message from root (pts/1) (Mon Oct 19 22:37:54 2009):

The system is going down for system halt NOW!
[root@xhlinux ~]#

 功能說明:關閉系統。

  語  法:halt [-dfinpw]

  補充說明:halt會先檢測系統的runlevel。若runlevel為0或6,則關閉系統,否則即呼叫shutdown來關閉系統。

  參  數:
  -d  不要在wtmp中記錄。
  -f  不論目前的runlevel為何,不呼叫shutdown即強制關閉系統。
  -i  在halt之前,關閉全部的網路介面。
  -n  halt前,不用先執行sync。
  -p  halt之後,執行poweroff。
  -w  僅在wtmp中記錄,而不實際結束系統。
具體使用可以查 man halt,man poweroff,建議reboot前執行sync, sycn;reboot

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12020513/viewspace-616917/,如需轉載,請註明出處,否則將追究法律責任。

相關文章