2.2Linux命令行接口及基础命令

命令的语法格式:
        COMMAND OPTIONS ARGUMENTS
选项和参数都是可以缺省的
        命令组成:
            系统自带命令
            应用程序
            脚本文件

            命令的类型:
                内建命令: 由shell程序自带的命令
                    查找方式:shell内建
                外部命令: 本身是一个独立的可执行程序文件,命令名即为程序文件名
                    查找方式:通过shell的内置的环境变量PATH中指定的路径进行查找;

                如何区分: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

        参数:
            命令的作用对象

        cd: change directory
            cd
            cd ~
            cd ~USERNAME
            cd -: 在前一个目录和当前目录之间反复切换

            两个独特的路径:
                .: 当前目录
                ..:上一级目录

        pwd: print working directory

        命令历史:bash的特性之一
            history  显示命令历史
终止当前命令的执行:Ctrl+c           
[root@linux_basic ~]# cd dlfjal^C
[root@linux_basic ~]#
            保存的条数:
                环境变量:HISTSIZE

            用户退出时的持久保存位置:
                环境变量:HISTFILE,通常默认为用户家目录下的.bash_history
                [root@linux_basic ~]# echo $HISTFILE
                /root/.bash_history

                此文件中可保存的最大数目:
                    环境变量: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
        外部命令:
            1、COMMAND --help  绝大部分命令都是支持的,获取命令简要帮助信息
            2、手册: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个

            3、info命令:获取在线文档
                仅在man手册无法获取到足够信息,或想了解程序的开发历史时才使用info

            4、很多应用程序都自带有帮助文档:/usr/share/doc/
                ChangeLog: 程序版本升级的变动情况
                INSTALL: 安装方法说明
                README:程序说明信息

            5、主流发行版官方文档
                redhat, suse, debian

                RedHat: http://www.redhat.com/docs/

            6、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

转载于:https://my.oschina.net/u/1762991/blog/662291

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值