第1章 Linux命令行简介

  • 1.1 Linux命令行概述

  • 1.2 在Linux命令行下查看命令帮助

  • 1.3 Linux关机、重启、注销命令

  • 1.4 老男孩的运维思想

  • 1.1 Linux命令行概述

    1.1.1 Linux命令行的作用与意义

      Linux是一个主要通过命令来进行管理的操作系统。

    1.1.2 Linux命令行介绍

    1)通过SSH工具远程连接阿里云ECS服务器,如Xshell;

    2)使用阿里云Web控制台-远程连接ECS服务器

    3)CentOS Linux命令行退出命令操作的界面

    1.1.3 Linux命令行常用快捷键

    常见的Linux远程连接工具:SecureCRT、Xshell客户端软件;

    1)最有用的快捷键;

    • tab 命令自动补全快捷键;

    2)移动光标快捷键;

    • Ctrl +a
    • Ctrl + e
    • Ctrl + f
    • Ctrl + b

    3)剪切、粘贴、清除快捷键;

    • Ctrl + Insert
    • Shift + Insert
    • Ctrl + k
    • Ctrl + u
    • Ctrl + w
    • Ctrl + y
    • Ctrl + e
    • Ctrl + h

    4)重复执行命令快捷键

    • Ctrl + d
    • Ctrl + r
    • Ctrl + g

    5)控制快捷键

    • Ctrl + l
    • Ctrl + s
    • Ctrl + q
    • Ctrl + z

    6)!开头的快捷键

    • !!
    • !pw
    • !pw:p
    • !num(指数字)
    • !$

    7)Esc相关

    • Esc + .
    • Esc + b
    • Esc + f

    1.2 在Linux命令行下查看命令帮助

    1.2.1 使用man获取命令帮助信息

    1)man命令的基本用法

      man命令是LInux系统中最核心的命令之一,可通过其查看其它Linux命令的使用、用法信息。还可查看软件服务配置文件、系统调用、库函数等帮助信息;

    2) 语法格式

    man 参数选项 命令/文件

    3)选项说明

    • User Commands 用户命令相关
    • System calls 系统函数调用
    • C Library Function C的库函数相关
    • Device and Special Files 设备和特殊文件相关
    • File Formats and Conventions 文件格式和规划
    • Games et.AI 游戏及其他
    • Miscellanea 宏、包及其他杂项
    • System Administration tools and Deamons 系统管理员命令和进程

    4)实战举例

    man man

    man cp

    man ls

    5) man帮助页的快捷键

    • Page Down
    • Page Up
    • Home
    • End
    • /cuixiaozhao
    • ?cuixiaozhao
    • n,N
    • q

    1.2.2 使用--help参数获取命令帮助信息

    复制代码
    [root@iZ2ze2m3z176dpbiaolifiZ ~]# cat --help
    Usage: cat [OPTION]... [FILE]...
    Concatenate FILE(s), or standard input, to standard output.
    

    -A, --show-all equivalent to -vET
    -b, --number-nonblank number nonempty output lines, overrides -n
    -e equivalent to -vE
    -E, --show-ends display $ at end of each line
    -n, --number number all output lines
    -s, --squeeze-blank suppress repeated empty output lines
    -t equivalent to -vT
    -T, --show-tabs display TAB characters as ^I
    -u (ignored)
    -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
    --help display this help and exit
    --version output version information and exit

    With no FILE, or when FILE is -, read standard input.

    Examples:
    cat f - g Output f's contents, then standard input, then g's contents.
    cat Copy standard input to standard output.

    GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
    For complete documentation, run: info coreutils
    'cat invocation'
    [root@iZ2ze2m3z176dpbiaolifiZ
    ~]# more --help
    more: unknown option -help
    Usage: more [options] file...

    Options:
    -d display help instead of ring bell
    -f count logical, rather than screen lines
    -l suppress pause after form feed
    -p do not scroll, clean screen and display text
    -c do not scroll, display text and clean line ends
    -u suppress underlining
    -s squeeze multiple blank lines into one
    -NUM specify the number of lines per screenful
    +NUM display file beginning from line number NUM
    +/STRING display file beginning from search string match
    -V output version information and exit
    [root@iZ2ze2m3z176dpbiaolifiZ
    ~]#

    复制代码

    小结:

    • 命令 --help 获取的是常用帮助信息;
    • man 命令 获取的更多更复杂的帮助信息;

    1.2.3 使用help命令获取bash内置命令帮助

    复制代码
    BASH_BUILTINS(1)                                                                                                        General Commands Manual                                                                                                        BASH_BUILTINS(1)
    

    NAME
    bash, :, ., [, alias, bg, bind, break, builtin, caller, cd, command, compgen, complete, compopt, continue, declare, dirs, disown, echo, enable, eval, exec, exit, export, false, fc, fg, getopts, hash, help, history, jobs, kill, let, local, logout, mapfile,
    popd, printf, pushd, pwd, read, readonly,
    return, set, shift, shopt, source, suspend, test, times, trap, true, type, typeset, ulimit, umask, unalias, unset, wait - bash built-in commands, see bash(1)

    BASH BUILTIN COMMANDS
    Unless otherwise noted, each builtin command documented in this section as accepting options preceded by - accepts -- to signify the end of the options. The :, true, false, and test builtins do not accept options and do not treat -- specially. The exit,
    logout,
    break, continue, let, and shift builtins accept and process arguments beginning with - without requiring --. Other builtins that accept arguments but are not specified as accepting options interpret arguments beginning with - as invalid options
    and require -- to prevent this interpretation.
    : [arguments]
    No effect; the command does nothing beyond expanding arguments
    and performing any specified redirections. A zero exit code is returned.

    复制代码

    举例如下:

    复制代码
    [root@iZ2ze2m3z176dpbiaolifiZ ~]# help cd
    cd: cd [-L|[-P [-e]]] [dir]
        Change the shell working directory.
    

    Change the current directory to DIR. The default DIR is the value of the
    HOME shell variable.

    The variable CDPATH defines the search path for the directory containing
    DIR. Alternative directory names
    in CDPATH are separated by a colon (😃.
    A null directory name
    is the same as the current directory. If DIR begins
    with a slash (
    /), then CDPATH is not used.

    If the directory is not found, and the shell option `cdable_vars' is set,
    the word is assumed to be a variable name. If that variable has a value,
    its value
    is used for DIR.

    Options:
    -L force symbolic links to be followed
    -P use the physical directory structure without following symbolic
    links
    -e if the -P option is supplied, and the current working directory
    cannot be determined successfully, exit with a non
    -zero status

    The default is to follow symbolic links, as if `-L' were specified.

    Exit Status:
    Returns 0
    if the directory is changed, and if $PWD is set successfully when
    -P is used; non-zero otherwise.
    [root@iZ2ze2m3z176dpbiaolifiZ
    ~]# help history
    history: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
    Display
    or manipulate the history list.

    Display the history list with line numbers, prefixing each modified
    entry with a `*'. An argument of N lists only the last N entries.

    Options:
    -c clear the history list by deleting all of the entries
    -d offset delete the history entry at offset OFFSET.

    -a append history lines from this session to the history file
    -n read all history lines not already read from the history file
    -r read the history file and append the contents to the history
    list
    -w write the current history to the history file
    and append them to the history list

    -p perform history expansion on each ARG and display the result
    without storing it
    in the history list
    -s append the ARGs to the history list as a single entry

    If FILENAME is given, it is used as the history file. Otherwise,
    if $HISTFILE has a value, that is used, else ~/.bash_history.

    If the $HISTTIMEFORMAT variable is set and not null, its value is used
    as a format string
    for strftime(3) to print the time stamp associated
    with each displayed history entry. No time stamps are printed otherwise.

    Exit Status:
    Returns success unless an invalid option is given or an error occurs.
    [root@iZ2ze2m3z176dpbiaolifiZ
    ~]#

    复制代码

    1.2.4 使用info获取帮助信息

    • info ls
    • info cd
    • info man

    1.2.5 通过互联网寻求帮助信息

    搜索引擎的使用优先顺序(建议)

    www.google.com ->www.bing.com ->www.baidu.com

    1.3 Linux关机、重启、注销命令

    1.3.1 重启或关机命令:shutdown

      shutdown总体来讲,是一个用来安全关闭或重启Linux系统的命令。

      与shutdown功能类似的有init halt poweroff reboot

    复制代码
    SHUTDOWN(8)                                                                                                                     shutdown                                                                                                                    SHUTDOWN(8)
    

    NAME
    shutdown - Halt, power-off or reboot the machine

    SYNOPSIS
    shutdown [OPTIONS...] [TIME] [WALL...]

    DESCRIPTION
    shutdown may be used to halt, power-off or reboot the machine.

    The first argument may be a time string (which is usually "now"). Optionally, this may be followed by a wall message to be sent to all logged-in users before going down.

    The time string may either be in the format "hh:mm" for hour/minutes specifying the time to execute the shutdown at, specified in 24h clock format. Alternatively it may be in the syntax "+m" referring to the specified number of minutes m from now. "now"
    is an alias for "+0", i.e. for triggering an immediate shutdown. If no time argument is specified, "+1" is implied.

    Note that to specify a wall message you must specify a time argument, too.

    If the time argument is used, 5 minutes before the system goes down the /run/nologin file is created to ensure that further logins shall not be allowed.

    OPTIONS
    The following options are understood:

    --help
    Print a short help text
    and exit.

    -H, --halt
    Halt the machine.

    -P, --poweroff
    Power
    -off the machine (the default).

    -r, --reboot
    Reboot the machine.

    -h
    Equivalent to
    --poweroff, unless --halt is specified.

    -k
    Do
    not halt, power-off, reboot, just write wall message.

    --no-wall
    Do
    not send wall message before halt, power-off, reboot.

    -c
    Cancel a pending shutdown. This may be used cancel the effect of an invocation of shutdown with a time argument that
    is not "+0" or "now".

    EXIT STATUS
    On success, 0 is returned, a non-zero failure code otherwise.

    SEE ALSO
    systemd(1), systemctl(1), halt(8), wall(1)

    Manual page shutdown(8) line 1 (press h for help or q to quit)

    复制代码

    shutdown实战举例

    • shutdown -h +1 #一分钟后关闭Linux操作系统
    • shutdown -c #取消shutdown操作
    • shutdown -r 11:11 #11:11重启Linux系统
    • shutdown -h now#now即现在,立刻关闭操作系统

    1.3.2 关机与重启命令:halt/poweroff/reboot

      从Redhat或CentOS6开始,这三者对应的man帮助信息都是同一个,而halt和poweroff命令是reboot命令的链接文件;

    • reboot 选项
    • halt 选项
    • poweroff 选项

    通常情况下,该3命令都不带任何参数

    复制代码
    [root@iZ2ze2m3z176dpbiaolifiZ ~]# ls /sbin/poweroff 
    /sbin/poweroff
    [root@iZ2ze2m3z176dpbiaolifiZ ~]# ls /sbin/halt 
    /sbin/halt
    [root@iZ2ze2m3z176dpbiaolifiZ ~]# ls /sbin/reboot 
    /sbin/reboot
    [root@iZ2ze2m3z176dpbiaolifiZ ~]# ls -l /sbin/poweroff 
    lrwxrwxrwx 1 root root 16 Oct 15  2017 /sbin/poweroff -> ../bin/systemctl
    [root@iZ2ze2m3z176dpbiaolifiZ ~]# ls -l /sbin/halt 
    lrwxrwxrwx 1 root root 16 Oct 15  2017 /sbin/halt -> ../bin/systemctl
    [root@iZ2ze2m3z176dpbiaolifiZ ~]# ls -l /sbin/reboot 
    lrwxrwxrwx 1 root root 16 Oct 15  2017 /sbin/reboot -> ../bin/systemctl
    [root@iZ2ze2m3z176dpbiaolifiZ ~]# 
    复制代码

    1.3.3 关机、重启和注销的命令列表

    1)关机命令

    • shutdown -h now
    • shutdown -h +1
    • halt
    • init 0
    • poweroff

    2)重启命令

    • reboot
    • shutdown -r now
    • shutdown -r +1
    • init 6

    3)注销命令

    • logout
    • exit
    • Ctrl + d(本质就是logout)

    1.4 老男孩的运维思想

      基础不牢,地动山摇!很多高大上的技术都是由细小的基础知识累积而成的!

      Linux命令正是组成Linux系统最核心的、重要的基础之一。牢牢掌握基础命令,方能在日后使用Linux时随心所欲。

     

    “终身”学习,生活充满诗意! 转载于https://www.cnblogs.com/tqtl911/p/9327087.html
    posted @ 2019-04-04 16:25  韦大仙  阅读(546)  评论(0)    收藏  举报