ITPub博客

首页 > Linux操作系统 > Linux操作系统 > linux基础学习(1)

linux基础学习(1)

原创 Linux操作系统 作者:fufuh2o 时间:2009-10-19 23:39:28 0 删除 编辑

切换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/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-06-26

  • 博文量
    182
  • 访问量
    426847